Repository navigation
Conversation
ibetitsmike
approved these changes
Oct 7, 2026
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 8, 2026
The agent netstack accepts connections through tcp.Forwarder and has no listening endpoint, so gVisor drops a SYN that reuses a 4-tuple the agent holds in TIME_WAIT, and the client's dial hangs for about 63s. The new pin is the head of coder/gvisor#4, which cherry-picks gvisor/gvisor#15019. That PR hands the SYN to the forwarder. It is open, from an outside contributor, and no gVisor maintainer has reviewed it.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 21, 2026
The agent netstack accepts connections through tcp.Forwarder and has no listening endpoint, so gVisor drops a SYN that reuses a 4-tuple the agent holds in TIME_WAIT, and the client's dial hangs for about 63s. The new pin is the head of coder/gvisor#4, which cherry-picks gvisor/gvisor#15019. That PR hands the SYN to the forwarder. It is open, from an outside contributor, and no gVisor maintainer has reviewed it.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2026
coder/gvisor#4 now also hands a SYN queued on a closing TIME_WAIT connection to the forwarder instead of answering it with RST.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2026
Picks up comment fixes only.
This comment was marked as outdated.
This comment was marked as outdated.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2026
Picks up comment changes only.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2026
coder/gvisor#4 now reopens TIME_WAIT only for a SYN without ACK, so a SYN-ACK no longer ends TIME_WAIT with a RST.
This comment has been minimized.
This comment has been minimized.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2026
coder/gvisor#4 now delivers the reopening SYN before the segments queued behind it, so a stale SYN in the queue no longer gets the SYN-ACK.
This comment was marked as outdated.
This comment was marked as outdated.
mafredri
marked this pull request as ready for review
October 29, 2026 20:44
mafredri
force-pushed
the
mafredri/forward-timewait-syn
branch
from
October 29, 2026 21:06
8fe8ec4 to
e31c917
Compare
mafredri
added a commit
to coder/coder
that referenced
this pull request
Oct 29, 2026
coder/gvisor#4 was rebuilt with its tests committed; the code is unchanged.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 3, 2026
The agent netstack accepts connections through tcp.Forwarder and has no listening endpoint, so gVisor drops a SYN that reuses a 4-tuple the agent holds in TIME_WAIT, and the client's dial hangs for about 63s. The new pin is the head of coder/gvisor#4, which cherry-picks gvisor/gvisor#15019. That PR hands the SYN to the forwarder. It is open, from an outside contributor, and no gVisor maintainer has reviewed it.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 3, 2026
coder/gvisor#4 now also hands a SYN queued on a closing TIME_WAIT connection to the forwarder instead of answering it with RST.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 3, 2026
Picks up comment fixes only.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 3, 2026
Picks up comment changes only.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 17, 2026
coder/gvisor#4 now delivers the reopening SYN before the segments queued behind it, so a stale SYN in the queue no longer gets the SYN-ACK.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 17, 2026
coder/gvisor#4 was rebuilt with its tests committed; the code is unchanged.
When a new SYN reopens a connection while the old incarnation is in TIME_WAIT (RFC 1122), handleTimeWaitSegments only looks for a bound listening endpoint to hand the segment to. A stack that accepts connections through a tcp.Forwarder has no such endpoint, so the SYN is dropped for the rest of the TIME_WAIT period. Fall back to the protocol's default handler, giving the forwarder the same chance a listening endpoint gets. Fixes gvisor#15013 Signed-off-by: drakeo338 <[email protected]> Cherry-picked from gvisor#15019 (unmerged)
…ment The reuseTW closure in handleTimeWaitSegments discarded the handler's return value. tcp.Forwarder.HandlePacket returns false for anything that is not a bare SYN, but a SYN-ACK with a higher sequence number still counts as a new SYN in TIME_WAIT, so it reached the handler, was declined, and was dropped without a reply. Send a RST as nic.DeliverTransportPacket does when the handler returns false. Adds a forwarder e2e test that sends a SYN-ACK during TIME_WAIT and expects a RST. Signed-off-by: drakeo338 <[email protected]> Cherry-picked from gvisor#15019 (unmerged)
tryDeliverSegmentFromClosedEndpoint replied with RST to any queued segment that matched no other endpoint, while nic.DeliverTransportPacket first offers such a segment to the protocol's default handler. On a stack that accepts through a tcp.Forwarder, a SYN retransmit queued on a TIME_WAIT endpoint behind the SYN that reopens it was drained with a RST before the reopening SYN reached the forwarder, so the peer saw RST then SYN-ACK and its connect failed with connection refused.
The default-handler fallback in handleTimeWaitSegments carried its own handler call and RST. tryDeliverSegmentFromClosedEndpoint now offers a segment that matches no endpoint to the default handler and replies with RST if it declines, so route the reopening SYN through it. The reopening SYN and the segments drained from the TIME_WAIT endpoint before it then follow one delivery rule.
Call it TransportProtocolHandler so the getter pairs with SetTransportProtocolHandler the way TransportProtocolOption pairs with SetTransportProtocolOption.
A SYN-ACK above RcvNxt counts as a new SYN in TIME_WAIT, but it is not a reopen. On a stack with no listener, redelivering it ended TIME_WAIT for that 4-tuple and drew a RST. Drop it instead, as before the default-handler fallback, so TIME_WAIT continues. TestForwarderTimeWaitRejectedGetsReset becomes TestForwarderTimeWaitSynAckKeepsTimeWait, and TestForwarderTimeWaitDeclinedSYNGetsReset covers the RST a declined SYN still gets.
A stale SYN queued behind the reopening SYN was drained first, reached the listener or default handler, and got the SYN-ACK, so the client reset it and connected only on its SYN retransmit. The listener path and google/gvisor master use the same order.
mafredri
force-pushed
the
mafredri/forward-timewait-syn
branch
from
November 18, 2026 10:57
e31c917 to
327336a
Compare
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
The agent netstack accepts connections through tcp.Forwarder and has no listening endpoint, so gVisor drops a SYN that reuses a 4-tuple the agent holds in TIME_WAIT, and the client's dial hangs for about 63s. The new pin is the head of coder/gvisor#4, which cherry-picks gvisor/gvisor#15019. That PR hands the SYN to the forwarder. It is open, from an outside contributor, and no gVisor maintainer has reviewed it.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
coder/gvisor#4 now also hands a SYN queued on a closing TIME_WAIT connection to the forwarder instead of answering it with RST.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
Picks up comment fixes only.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
Picks up comment changes only.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
coder/gvisor#4 now reopens TIME_WAIT only for a SYN without ACK, so a SYN-ACK no longer ends TIME_WAIT with a RST.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
coder/gvisor#4 now delivers the reopening SYN before the segments queued behind it, so a stale SYN in the queue no longer gets the SYN-ACK.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
coder/gvisor#4 was rebuilt with its tests committed; the code is unchanged.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 18, 2026
coder/gvisor#4 was rebased onto new-coder-main with an identical tree, and the previous pinned commit is no longer on any coder/gvisor branch.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
The agent netstack accepts connections through tcp.Forwarder and has no listening endpoint, so gVisor drops a SYN that reuses a 4-tuple the agent holds in TIME_WAIT, and the client's dial hangs for about 63s. The new pin is the head of coder/gvisor#4, which cherry-picks gvisor/gvisor#15019. That PR hands the SYN to the forwarder. It is open, from an outside contributor, and no gVisor maintainer has reviewed it.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
coder/gvisor#4 now also hands a SYN queued on a closing TIME_WAIT connection to the forwarder instead of answering it with RST.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
Picks up comment fixes only.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
Picks up comment changes only.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
coder/gvisor#4 now reopens TIME_WAIT only for a SYN without ACK, so a SYN-ACK no longer ends TIME_WAIT with a RST.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
coder/gvisor#4 now delivers the reopening SYN before the segments queued behind it, so a stale SYN in the queue no longer gets the SYN-ACK.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
coder/gvisor#4 was rebuilt with its tests committed; the code is unchanged.
mafredri
added a commit
to coder/coder
that referenced
this pull request
Nov 25, 2026
coder/gvisor#4 was rebased onto new-coder-main with an identical tree, and the previous pinned commit is no longer on any coder/gvisor branch.
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.
Delivers a SYN that reopens a 4-tuple in TIME_WAIT to the stack's default handler when no listening endpoint matches it. Tailscale's netstack, which Coder workspace agents use, accepts TCP through a
tcp.Forwarderand has no listening endpoint, so the SYN and every retransmit were dropped until TIME_WAIT expired, and the client's dial hung for up to about 63s (gvisor#15013). This is the reopen RFC 1122 allows, a SYN above the old connection'sRcvNxt. A reopening SYN at or below it is a separate bug, tracked in CORE-809.Upstream's forwarder e2e test and the helpers it imports are on
new-coder-mainsince #8.The first two commits cherry-pick gvisor#15019 at
e503a89e8, an open PR from an outside contributor, with its tests. The other commits are ours, each with the test for its change:nic.DeliverTransportPacket. It gets a RST only if there is no default handler or the handler returns false. Before, a duplicate of the reopening SYN queued behind it got a RST, and the client's dial failed with "connection refused".RcvNxtended TIME_WAIT for its 4-tuple and got a RST. Now it is dropped and TIME_WAIT continues.handleTimeWaitdelivers the reopening SYN before draining the endpoint's queue. Before, a stale SYN queued behind it reached the handler first and got the SYN-ACK, so the client reset it and connected only on its 1s retransmit. The listener path and upstream master have the same order.TransportProtocolDefaultHandleris renamedTransportProtocolHandler, so it pairs withSetTransportProtocolHandlerasTransportProtocolOptionpairs withSetTransportProtocolOption.Fixes CORE-717
Testing
Nothing in this repository runs tests, so run them by hand. Every commit builds and passes its tests:
TestForwarderReopenAfterTimeWait(from tcp: forward SYN in TIME_WAIT to the protocol handler gvisor/gvisor#15019) fails on the base and passes here.TestForwarderReopenAfterTimeWaitDuplicateSYNfails at the tcp: forward SYN in TIME_WAIT to the protocol handler gvisor/gvisor#15019 cherry-pick and passes here.TestForwarderTimeWaitSynAckKeepsTimeWaitreplaces tcp: forward SYN in TIME_WAIT to the protocol handler gvisor/gvisor#15019'sTestForwarderTimeWaitRejectedGetsResetin the commit that drops the SYN-ACK, since that test expects the RST this branch no longer sends.TestForwarderTimeWaitDeclinedSYNGetsResetcovers a default handler that returns false for the reopening SYN.TestForwarderReopenAfterTimeWaitStaleSYNfails without thehandleTimeWaitreorder and passes here.pkg/tcpip/transport/tcp/...andpkg/tcpip/stack/...from upstreama5b10b7ddpass against this branch in a scratch copy, including the existing TIME_WAIT tests, and the-racerun is clean.coder/coder#30471 pins this branch's head.
When squash-merging, use this message instead of the default list of commit messages: