Repository navigation
Fix idle WebSocket detach during resume - #4
Merged
Merged
Conversation
Contributor
Reviewer's GuideFix resumable WebSocket replacement by pairing outbound-pipe interrupts with an attachment-owned cancellation context, ensuring an idle old writer exits instead of re-parking; add regression coverage that verifies resume succeeds and the replacement replays buffered data. Sequence diagram for resumable WebSocket replacementsequenceDiagram
participant Replacement as ReplacementWebSocket
participant Handler as WebSocketHandler
participant Attachment as Attachment
participant OldWriter as OldWritePump
participant Pipe as OutboundPipe
participant OldSocket as OldWebSocket
Replacement->>Handler: /resume
Handler->>Attachment: attach(attachBoth, kick)
Attachment->>Handler: kick old attachment
Handler->>OldWriter: cancel()
Handler->>OldSocket: CloseNow()
Handler->>Pipe: interruptOut()
Pipe-->>OldWriter: errPipeInterrupted
OldWriter->>OldWriter: ctx.Err()
OldWriter-->>Handler: return context.Canceled
Handler-->>Replacement: resume succeeds
Sequence diagram for replacement replaying buffered WebSocket datasequenceDiagram
participant Client as ResumingClient
participant NewHandler as NewWebSocketHandler
participant Session as Session
participant NewWriter as NewWritePump
participant ClientSocket as NewWebSocket
Client->>NewHandler: /resume
NewHandler->>Session: attach(attachBoth, kick)
NewHandler->>NewWriter: wsWritePumpResumable()
NewWriter->>Session: nextOut()
Session-->>NewWriter: buffered data
NewWriter->>ClientSocket: Write buffered data
ClientSocket-->>Client: replayed data
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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
/resumekicks an attachment, while preserving harmless ACK/state interruptsRoot cause
v0.2.1 correctly stopped treating every
errPipeInterruptedas a transport failure. However, when/resumeclosed and interrupted an idle server WebSocket with no ACK due, the write pump cleared the interrupt and parked innextOutagain. Repeated resume attempts kept waking and re-parking it, so the old attachment never detached and/resumereturned 503 until the grace period expired.The attachment-owned context now distinguishes replacement/shutdown from a harmless interrupt. The interrupt wakes
nextOut, and the cancelled context makes the old write pump return immediately.Tests
go test ./...go test -race ./...-count=5-count=20TestIntegration_ResumableWebSocketwith-count=3against this branchgo test ./...against this branchSummary by Sourcery
Ensure idle resumable WebSocket connections detach cleanly during resume so replacement connections can reconnect and replay pending data.
Bug Fixes:
/resumereplacement, allowing the old connection to detach and the replacement to succeed immediately.Enhancements:
Tests: