Repository navigation
Fix resumable transport spin after interrupts - #3
Merged
Merged
Conversation
Contributor
Reviewer's GuideFix resumable transport spin by consuming interrupt wake-ups correctly and adding a defensive supervisor guard that abandons sessions after five consecutive fast, no-progress replacement-leg failures while preserving productive recovery. Sequence diagram for resumable transport interrupt handlingsequenceDiagram
participant Leg as Resumable leg
participant Writer as WebSocket or stream writer
participant Pipe as Shared pipe
participant Transport as Transport
Pipe->>Writer: errPipeInterrupted wake-up
Writer->>Writer: Clear err after handling interrupt
Writer->>Writer: Check pending acknowledgement
Writer->>Transport: Continue write loop
Note over Writer,Transport: Wake-up is not reported as a transport failure
Flow diagram for bounded resumable session recoveryflowchart TD
A[runLegs] --> B[Measure leg duration and progress]
B --> C{Stable for 2 seconds or progress observed?}
C -->|Yes| D[Reset consecutiveFast]
C -->|No| E[Increment consecutiveFast]
D --> F[Resume session]
E --> G{Five fast failures reached?}
G -->|No| F
G -->|Yes| H[fail and abandon session]
F --> A
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="resume_test.go" line_range="911-912" />
<code_context>
+ // Let both pumps settle into their idle waits, then inject the same
+ // harmless wake-up used by attachment replacement and eager acknowledgements.
+ time.Sleep(50 * time.Millisecond)
+ rc.rl.interruptOut()
+ time.Sleep(3 * e.cfg.HeartbeatInterval)
+
+ if got := e.resumes.Load(); got != 0 {
</code_context>
<issue_to_address>
**nitpick (testing):** The client interrupt regression relies on fixed sleeps rather than observing that both transport pumps have reached their idle waits. On a slow or heavily scheduled run, the interrupt can be injected before the intended code path is active, so the test can pass without exercising the no-ACK interrupt handling it claims to cover.
**Triggers:** When the test machine has scheduling or startup delays longer than the 50 ms settling sleep.
**Suggested fix:** Wait for an explicit server/client readiness signal or otherwise synchronize on the pumps entering their wait state instead of using fixed sleeps.
</issue_to_address>
Owner
Author
|
@sourcery-ai review |
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="reliable.go" line_range="233-236" />
<code_context>
+// progress snapshots the cumulative byte counts in both directions. The
+// supervisor uses it to distinguish a rapidly failing but productive series
+// of transports from a resume loop that never moves the session at all.
+func (r *reliable) progress() reliableProgress {
+ r.mu.Lock()
+ defer r.mu.Unlock()
+ return reliableProgress{sent: r.sendOffset, recv: r.recvOffset}
+}
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The fast-resume guard treats changes to `sendOffset` or `recvOffset` as transferred progress, but those offsets advance before the transport write succeeds. A replacement leg that consumes bytes from `nextOut` and then immediately fails its WebSocket or stream write therefore resets the guard even though no bytes reached the peer, allowing the successful-handshake/dead-leg spin to continue indefinitely.
**Triggers:** When outbound data is available and each replacement leg reads it from the reliable pipe but fails before writing it to the transport.
**Suggested fix:** Track bytes successfully written or acknowledged by the leg, rather than using cumulative application offsets that advance during reads from the local pipe.
</issue_to_address>
Owner
Author
|
@sourcery-ai review |
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
errPipeInterruptedas an internal wake-up in resumable WebSocket and stream writers instead of leaking it as a transport failureBackground
A resumable WebSocket session could enter a tight loop where
/resumereturned 200 but the replacement legs immediately failed withpollmux: pipe wait interrupted. Since resume request backoff only applies to failed handshakes, this produced repeated resumes without delay and could leave a tunnel unavailable indefinitely.errPipeInterruptedis a level-triggered internal wake-up, not an I/O failure. The WebSocket write paths handled the signal but left it in the sharederrvariable, so it escaped whenever no ACK was due.The targeted fix clears that handled sentinel. A no-progress fast-resume guard is included as defense in depth against any future defect with the same successful-handshake/dead-legs shape.
Release
v0.2.1ProtocolVersionremains 1 because the wire format is unchanged and mixed-version deployments remain compatibleTesting
go test -count=1 ./...go test -race-count=10git diff --checkSummary by Sourcery
Prevent resumable transports from spinning after interrupted or non-progressing replacement legs.
Bug Fixes:
Enhancements:
Tests: