Skip to content

Fix resumable transport spin after interrupts - #3

Merged
DiamondGo merged 3 commits into
mainfrom
fix/resume-legs-spin
Sep 8, 2026
Merged

DiamondGo merged 3 commits into
mainfrom
fix/resume-legs-spin

Conversation

@DiamondGo

@DiamondGo DiamondGo commented Sep 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • consume errPipeInterrupted as an internal wake-up in resumable WebSocket and stream writers instead of leaking it as a transport failure
  • abandon a resumable session after five consecutive fast, no-progress leg failures, allowing the outer reconnect loop to establish a fresh session
  • reset the fast-failure guard when a leg is stable or transfers bytes, preserving productive recovery on flaky links
  • add client/server WebSocket interrupt regressions and an end-to-end successful-resume/dead-legs spin test

Background

A resumable WebSocket session could enter a tight loop where /resume returned 200 but the replacement legs immediately failed with pollmux: 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.

errPipeInterrupted is a level-triggered internal wake-up, not an I/O failure. The WebSocket write paths handled the signal but left it in the shared err variable, 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

  • patch release: v0.2.1
  • ProtocolVersion remains 1 because the wire format is unchanged and mixed-version deployments remain compatible

Testing

  • go test -count=1 ./...
  • targeted resume/WebSocket tests under go test -race
  • new regression tests repeated with -count=10
  • git diff --check

Summary by Sourcery

Prevent resumable transports from spinning after interrupted or non-progressing replacement legs.

Bug Fixes:

  • Prevent internal pipe-interrupt wake-ups from being reported as WebSocket or stream transport failures.
  • Bound repeated successful resumes with immediately failing replacement legs by abandoning the session after five consecutive fast, non-progressing attempts.

Enhancements:

  • Track peer-visible transfer progress and reset the fast-resume failure guard when a leg remains stable or transfers data.

Tests:

  • Add client and server WebSocket interrupt regressions and an end-to-end test covering abandonment after repeated dead resumable legs.

@sourcery-ai

sourcery-ai Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Fix 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 handling

sequenceDiagram
    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
Loading

Flow diagram for bounded resumable session recovery

flowchart 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
Loading

File-Level Changes

Change Details Files
Treat pipe interrupts as internal wake-ups rather than transport failures.
  • Clear the handled interrupt sentinel in resumable stream and WebSocket write paths.
  • Preserve current attachments when an interrupt occurs without an acknowledgement.
  • Add client and server WebSocket regressions for interrupt handling.
handler.go
resumable_client.go
resume_test.go
websocket.go
Bound repeated successful resumes that produce immediately failing replacement legs.
  • Track consecutive fast, no-progress leg failures and abandon the session after five.
  • Reset the guard when legs remain stable for two seconds or demonstrate peer-visible progress.
  • Add an end-to-end test covering successful resume handshakes followed by dead WebSocket legs.
resumable_client.go
resume_test.go
Define progress using evidence visible to the peer.
  • Snapshot acknowledged outbound bytes and received inbound bytes under the reliable-state lock.
  • Include resume-handshake receive offsets as progress while excluding local-only send-offset advancement.
  • Add unit coverage for acknowledgements, resume offsets, and received bytes.
reliable.go
reliable_test.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread resume_test.go Resolved
@DiamondGo

Copy link
Copy Markdown
Owner Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread reliable.go Resolved
@DiamondGo

Copy link
Copy Markdown
Owner Author

@sourcery-ai review

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@DiamondGo
DiamondGo merged commit 2cf104a into main Sep 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants