Skip to content

Fix missing instance ticket token JNI binding - #1552

Merged
bmehta001 merged 4 commits into
mainfrom
user/xingyu/fix-instance-ticket-token-jni
Nov 5, 2026
Merged

bmehta001 merged 4 commits into
mainfrom
user/xingyu/fix-instance-ticket-token-jni

Conversation

@star-du

@star-du star-du (star-du) commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Calling ILogManager.setTicketToken on a manager created by LogManagerProvider throws UnsatisfiedLinkError: Java declares the instance native method, but the corresponding JNI entry point is missing.

Implement the bridge to the instance auth tokens controller and return its status. Invalid managers or unavailable controllers return EFAIL; pending Java string-conversion exceptions are preserved. The existing static entry point remains unchanged.

Also address the controller risks exposed by this call path:

  • Serialize token updates, clears, and SDK readers during HTTP header encoding and event decoration.
  • Register each user ticket key only once, preventing repeated refreshes from growing memory and subsequent event payloads.
  • Add regression tests for repeated refreshes, clear/re-registration, and concurrent writers with active encoding and decoration.

The internal SDK-wide lock preserves the existing public API and object layout. It serializes token access across manager instances. Applications using the legacy reference-returning getters must still avoid accessing those live references concurrently with updates; this requirement is documented in the interface.

Related: #1218 (closed without merging).

Validation

  • Windows / Visual Studio 2026: 51 targeted controller, encoder, decorator, and LogManagerImpl tests passed.
  • WSL / Clang 18 / ThreadSanitizer: all 42 selected controller, encoder, and decorator tests passed with halt_on_error=1, without sanitizer suppressions or disabled tests.
  • Regression checks against the original PR code: the new deduplication test fails, and concurrent token refresh triggers a ThreadSanitizer data-race report in AuthTokensController::SetTicketToken. Both pass with the fixes.
  • Public-header gates passed on Windows/MSVC and Linux/GCC/Clang, including exception-disabled configurations.
  • Changed-lines clang-format, git diff --check, and the same hash-verified misspell release used by CI passed on all changed files.

A broader sanitizer run also found a separate, pre-existing vptr race during TestLogManagerImpl construction (TransmissionPolicyManager.cpp:19). That race was reproduced against the original PR code and remains unchanged and unsuppressed; the 42-test sanitizer pass above does not include the LogManagerImpl suite.

No Android device or Java-to-JNI runtime tests were run locally.

Implement the existing Java native contract through the instance auth tokens controller while preserving status and conversion failures.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@star-du
star-du (star-du) requested a review from a team as a code owner October 30, 2026 08:11
@star-du

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company="Microsoft"

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are recorded for the new instance ticket-token JNI binding.

No open issues 🎉

What changed in this PR

Adds the missing JNI binding for ILogManager.setTicketToken on managers created by LogManagerProvider, resolving the reported UnsatisfiedLinkError.

Changes:

  • Delegates to the instance authentication tokens controller and returns its status.
  • Returns EFAIL for unavailable managers or controllers and preserves pending Java string-conversion exceptions.
  • Leaves the existing static entry point unchanged.
File Description
lib/​jni/​LogManager_jni.cpp Implements the instance ticket-token JNI entry point with failure handling.

Review effort: Balanced

@bmehta001 bmehta001 self-assigned this Nov 5, 2026
bmehta001 and others added 2 commits November 5, 2026 00:26
Prevent token refresh and clear operations from racing with HTTP header encoding and event decoration. Use an internal SDK-wide lock to preserve the public API and object layout, and document the synchronization requirement for legacy live-reference getters.

Register each user ticket key only once so repeated refreshes do not grow memory and every subsequent event payload. Cover refresh, clear/re-registration, and concurrent writers with active SDK readers.

Validation: 51 targeted tests passed with VS 2026; 42 token/encoder/decorator tests passed under WSL Clang ThreadSanitizer. Public-header gates, changed-lines clang-format, diff whitespace, and CI misspell passed. The original code fails the new deduplication test and reports a token race under ThreadSanitizer. A separate pre-existing LogManagerImpl construction vptr race was reproduced on the original code and is not suppressed or modified here.

Files changed:
- lib/api/AuthTokensController.cpp
- lib/api/AuthTokensController.hpp
- lib/decorators/BaseDecorator.cpp
- lib/http/HttpRequestEncoder.cpp
- lib/include/public/IAuthTokensController.hpp
- tests/unittests/HttpRequestEncoderTests.cpp

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0d8996b4-37b3-4519-870a-4ce3be753d08
@bmehta001
bmehta001 enabled auto-merge (squash) November 5, 2026 07:06
@bmehta001
bmehta001 merged commit bc49ccc into main Nov 5, 2026
96 checks passed
@bmehta001
bmehta001 deleted the user/xingyu/fix-instance-ticket-token-jni branch November 5, 2026 07:18
@bmehta001

Copy link
Copy Markdown
Contributor

Thanks star-du (@star-du) for your contribution. I have hardened and merged in your PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants