Session Manager Concurrency Fix #1419
Open
+272
−49
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #1: Session Manager Concurrency Fix
Description
The changes fix a thread-safety issue in SessionManager where concurrent calls to
getSessionId()could create duplicate sessions during session timeout/expiration.
Problem
The existing code had a documented TODO acknowledging this race condition:
Solution:
Related PRs
This is part 1 of 3 in a session management enhancement:
This PR: Thread-safety fix (foundation)
PR 2: Session infrastructure (depends on this)
PR 3: Session telemetry integration (depends on PR 2)
Review order: This PR should be reviewed and merged first.
Type of Change
[x] Bug fix (non-breaking change which fixes an issue)
[ ] New feature
[ ] Breaking change
[x] Documentation update
Checklist
[x] Code follows project style guidelines (spotless applied)
[x] Self-review completed
[x] Added tests that prove the fix is effective
[x] New and existing tests pass locally
[x] Documentation updated where applicable
Additional Context
This uses the atomic compare-and-set pattern commonly used for thread-safe operations in Java/Kotlin.
Part of a larger effort: We're contributing session management enhancements to bring Android SDK to parity with iOS (spans/logs) and beyond (metrics). This PR is the foundation - fixing a known thread-safety issue before building on it.
Related information: https://opentelemetry.io/docs/specs/semconv/general/session/
Related PRs
This is part 1 of 3 in a comprehensive session management enhancement:
Review order: This PR should be reviewed and merged first, as PRs 2 and 3