Repository navigation
Add atomic idle session close - #1
Merged
Merged
Conversation
Add CloseSessionIfNoPollInFlight and synchronize poll, stream, WebSocket, sweeper, and close lifecycle transitions. Cover transport races and exactly-once disconnect behavior, fix race-prone test state, and ignore cross-repo plans.
Contributor
Reviewer's GuideAdds an atomic idle-session close path and applies a single store-to-session lifecycle locking protocol across polls, WebSockets, unconditional close, and sweeping, while keeping pipe cleanup and callbacks outside locks and adding broad race-focused test coverage. Sequence diagram for atomic idle session closesequenceDiagram
participant Caller
participant SessionStore
participant Session
participant Hooks
Caller->>SessionStore: CloseSessionIfNoPollInFlight(st, h, s, reason)
SessionStore->>SessionStore: removeAndMarkClosed(s, true)
SessionStore->>Session: lock lifecycle state
alt current entry and pollInFlight == 0
SessionStore->>Session: mark closed and delete from store
SessionStore-->>Caller: true
Caller->>Session: closePipes()
Caller->>Hooks: OnDisconnect(s, reason)
else replaced, closed, or attached transport
SessionStore-->>Caller: false
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="session.go" line_range="58-59" />
<code_context>
// drops immediately, which is what turns a silent client death into a fast
// detection instead of a session_timeout wait (A3).
- pollInFlight atomic.Int32
+ pollInFlight int32
mu sync.Mutex
</code_context>
<issue_to_address>
**nitpick:** The field comment still says `pollInFlight` counts only long polls and describes a parked TCP connection, but the new implementation also counts send-only requests, stream requests before they park, and WebSocket attachments. Users relying on the field's documented meaning can incorrectly treat a nonzero value as proof of a parked long poll or miss that it represents a WebSocket transport.
**Suggested fix:** Update the field comment to describe all lifecycle attachments counted by `pollInFlight`, or move the lifecycle-specific explanation to `PollInFlight` and remove the stale long-poll-only wording.
```suggestion
// pollInFlight counts active poll requests and persistent transports attached
// to the session, including send-only requests, stream requests before they
// park, and WebSocket attachments. A nonzero value means a client transport
// is currently attached and prevents eviction; it does not necessarily mean
// a long poll is parked.
```
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
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
CloseSessionIfNoPollInFlight, which atomically closes only the current, idle store entryOnDisconnect, with application callbacks outside internal locksPollInFlightas an observational snapshot rather than a lifecycle decision API.gitignoreupdate for the cross-repositoryplansdirectoryv0.1.6Tests
go test ./... -count=5go test -race ./... -count=1Coverage includes batch and stream polls, WebSocket attach/detach, store identity, closed-session HTTP behavior, and races against normal close, DELETE, and the sweeper.
Summary by Sourcery
Make idle session closure atomic and race-safe across all session lifecycle operations.
New Features:
Bug Fixes:
Enhancements:
Tests:
Chores: