fix: serialize AutoSession creation with Session.Close - #260
Merged
Conversation
Associate an AutoSession with its Request before publishing it, and commit session cookies only while the exact Session remains registered and live. Share the cookie commit with manual and middleware-created Sessions so reentrant response writers cannot emit stale live cookies. Add deterministic WebSocket and middleware regressions for close-during-publication behavior.
Exercise the deadline half of the live-session cookie guard and document why it is distinct from Close serialization. Apply the related review cleanups and remove obsolete recoverable CSPRNG failure claims.
Restore the scoped deferred unlock around session allocation so an error from a replacement random reader cannot wedge Jaws. Pin the nil-request contract and both halves of the live-session publication guard.
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
Fixes #249.
Concurrency model
AutoSession creation follows the established Jaws -> Request -> Session lock order. Both sides of the Request/Session association are established before registry insertion, so Sessions never exposes a half-associated AutoSession.
Cookie publication calls ResponseWriter.Header with no internal lock held, then holds Jaws and Session read locks through the concrete response/request header mutations. If cookie publication wins, a later Close sees and detaches the associated Request and queues one reload. If Close wins, no live response or request cookie is installed.
Creation remains in the 101 Switching Protocols hook, preserving the accepted-handshake-only behavior from #139.
Tests
Verification