Refactor session manager to use simpler concurrency control [2/3]#6631
Closed
glightfoot wants to merge 2 commits into
Closed
Refactor session manager to use simpler concurrency control [2/3]#6631glightfoot wants to merge 2 commits into
glightfoot wants to merge 2 commits into
Conversation
Signed-off-by: Greg Lightfoot <greg.lightfoot@reddit.com>
4 tasks
Signed-off-by: Greg Lightfoot <greg.lightfoot@reddit.com>
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR refactors
session.Managerto use simpler, more deterministic concurrency control and removes global condition-variable wakeup behavior that caused unnecessary contention under load.The implementation replaces shared mutable state guarded by
sync.Mutex+sync.Condwith a single-owner state model and explicit per-session wait coordination.This is part of the changes we run in our fork, along with #6630 and #6632, but broken out into separate PRs to make it easier to review. We have been running this change in our internal fork with no issues.
Motivation
The previous manager implementation relied on:
Under churn (many waiters + session creation/cancellation), this could lead to avoidable wakeup storms and poor tail latency for unrelated lookups.
What Changed
Session manager concurrency model
sessionStatewith explicit buckets:activesessionsreservedsession IDs (creation in progress)pendingwaiters per session IDchan *sessionState) and helper methods (withState,tryWithState) for serialized state mutation.Cond.Broadcast()wakeups with targeted per-session waiter notification (pendingWait/notifyPending/releasePendingWait).Session lifecycle handling
reserve -> activate -> removelifecycle to prevent duplicate registration races.HandleHTTPRequestandHandleConnthrough a sharedrunSessionflow with clear setup/session/cleanup phases.Getbehavior improvementsnoWait=truereturns immediately if no active session).Test Coverage
This PR adds broad test coverage for correctness and concurrency behavior, including:
session/manager_test.gosession/manager_concurrency_test.gosession/group_test.goAny()edge cases, callback errors, and high-concurrency access patternsImpact
Get,HandleConn, andHandleHTTPRequestoperations.Fixes #6633