Repository navigation
Add resumable sessions: yamux survives transport failures - #2
Merged
Merged
Conversation
Implement plans/pollmux-resumable-session-design.md. A session that
negotiates Resumable (client PreferResume && server EnableResume, on
WebSocket or two-way stream mode) keeps its yamux session and every
stream alive across a transport failure: the client resumes the same
session id through POST {prefix}/{id}/resume instead of reconnecting.
- reliable.go: the byte layer shared by both ends. Data frames become
frameSeqData carrying an absolute offset; frameAck acknowledges.
Unacknowledged bytes are retained for replay; the receiver dedups by
offset and refuses gaps. Overflowing MaxReplayBytes only ends
resumability, never a live connection.
- resume_server.go: one attachment per direction on the server (a newer
transport kicks a stale one and waits for it to leave), and
ResumeHandler, which exchanges recv offsets after kicking whatever is
still attached.
- resumable_client.go: resumableConn, whose supervisor tears down failed
legs, resumes with backoff within the server's grace, and only falls
back to TransportFailed when resuming is impossible.
- Session/SessionStore: detached resumable sessions live for ResumeGrace
instead of SessionTimeout, are refused by CloseSessionIfNoPollInFlight
while in grace, and are capped by MaxDetachedResumable.
- BufferedPipe.interrupt: level-triggered wake for ReadAvailable, used to
detach stale writers promptly and to send eager acks.
Negotiation is purely additive; old and new binaries mix freely and
batch mode never resumes. §17 of the plan records where the
implementation deviates from the design and why.
Tests: unit tests for the reliable layer, frame codec, pipe interrupt
and attachments; handler-level tests for the handshake, deterministic
seam-loss replay, dedup/gap handling, grace/sweeper/conditional-close
behaviour; end-to-end tests through a fault-injecting TCP proxy for
stream and WebSocket (repeated kills mid-transfer, idle kills, grace
expiry, degradation paths, probe fallback, replay overflow); and a
two-hop relay test where both hops are killed and the tunnelled stream
survives.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vJHFMFrjk4Y3qcWW1eWHh
Contributor
There was a problem hiding this comment.
Sorry @DiamondGo, your pull request is larger than the review limit of 150,000 diff characters
… docs - resumableConn.ws becomes an atomic.Pointer. Close already ordered its read after the supervisor's writes via wg.Wait, but the safety of that should not hinge on a reader knowing the ordering. - resume's backoff gets ±20% jitter: the failure this feature exists for (a CDN closing every connection at its maximum age) hits a fleet of clients in the same second, and they should not all retry on one beat. - BufferedPipe.ReadAvailable documents that errPipeInterrupted says nothing about the pipe's contents: an interrupt landing during the coalesce window is reported on the following call, after that call's data has been returned, so callers must only re-check and call again. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vJHFMFrjk4Y3qcWW1eWHh
Owner
Author
|
Addressed the review in the latest commit:
Full suite, |
…dary Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vJHFMFrjk4Y3qcWW1eWHh
Owner
Author
|
Review item 3 (offset validation /
|
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
Implements
plans/pollmux-resumable-session-design.md: an opt-in, purely additive resumable session mode. When both ends enable it (clientConnector.PreferResume, serverServerConfig.EnableResume) on WebSocket or two-way stream transport, a transport failure no longer kills the yamux session. The client resumes the same session id viaPOST {prefix}/{id}/resume, both sides replay the bytes lost at the seam, and every stream (e.g. an SSH connection through the tunnel) carries on. This is the fix for the "CDN max-connection-age kills the tunnel once an hour" problem described in the design.What changed
reliable.go— the byte layer shared verbatim by client and server. Data frames on a resumable session areframeSeqData(8-byte absolute offset + data);frameAckacknowledges cumulatively. Unacked bytes are retained for replay; receivers dedup by offset and refuse gaps. ACKs piggyback on reverse traffic and are sent eagerly after half a yamux window. ExceedingMaxReplayBytesonly ends resumability — a live connection keeps working.resume_server.go— one attachment per direction on the server: a newer transport kicks a stale one (pipe interrupt + write/read deadline /CloseNow) and waits for it to leave, so offsets are trustworthy and the stream is never interleaved.ResumeHandlerperforms the offset exchange (200/404/409/410/426/503 semantics documented on the handler).resumable_client.go—resumableConn: yamux is built once; a supervisor tears down failed legs, resumes with backoff within the server-handedresume_grace_ms, and only closesTransportFailedwhen resuming is impossible (session gone, offsets unhonourable, replay overflow, grace exhausted).ReconnectLoopis unchanged and remains the fallback.Session/SessionStore— detached resumable sessions are judged byResumeGrace(default 30s, capped at 5m) instead ofSessionTimeout;CloseSessionIfNoPollInFlightrefuses them while in grace (so a periodic reaper like HttpBroker's needs no change);MaxDetachedResumablecaps the memory a burst of disconnects can hold;Session.Resumable()/ResumeDeadline()for observability.BufferedPipe.interrupt— level-triggered wake forReadAvailable; unexported, unused by non-resumable paths.ConnectRequest.PreferResume,ConnectResponse.Resumable,Limits.ResumeGraceMS.ProtocolVersionunchanged; old×new in either direction degrades to today's behaviour; batch mode never negotiates resume. If the upload auto-probe fails on a resumable connect, the client deletes that session and reconnects once without resume.Deviations from the design are recorded in §17 of the plan (notably: data frames must carry offsets for dedup to be possible; the
frameResumeframe was not needed). README gains a "六、跨重连会话恢复" section.Tests
SessionTimeout, conditional close, detached cap, DELETE race with hook exactly-once.TransportFailed+ eviction; server-closed session not resurrected; server-off / client-not-asking degrade; probe failure fallback; replay overflow gives up cleanly.go test ./...,go test -race ./..., and the resume suite at-count=15all pass.Follow-up (HttpBroker repo)
Config passthrough for
PreferResume/EnableResume/ResumeGrace, mountResumeHandlerbehind the same auth middleware, and enable it on both hops.🤖 Generated with Claude Code
https://claude.ai/code/session_012vJHFMFrjk4Y3qcWW1eWHh