Skip to content

tcp: forward SYN in TIME_WAIT to the protocol handler - #17844

Open
adios-404 wants to merge 1 commit into
gvisor:masterfrom
adios-404:carry-15019-timewait-forwarder
Open

adios-404 wants to merge 1 commit into
gvisor:masterfrom
adios-404:carry-15019-timewait-forwarder

Conversation

@adios-404

Copy link
Copy Markdown
Contributor

Squashed and rebased copy of #15019 by @drakeo338, who is kept as the commit author, as carzh asked on that PR. It also folds in tamird's 936ad90db for carzh's duplicate-SYN case, with tamird as co-author.

The only conflict was #15094's segment-leak fix in the listener path; the copy keeps both. TestForwarderReopenWithDuplicateSyn queues two copies of the reopening SYN before the TIME_WAIT endpoint runs: without 936ad90 the stack sends a RST first, and with it the connection reopens.

On today's master, bazel test //pkg/tcpip/transport/tcp/... //pkg/tcpip/stack/... passes (39 of 39) and the forwarder tests pass 20 runs in a row. Earlier, the new test passed 50 of 50 runs, and the forwarder tests passed 20 runs each under go test -race.

A Tailscale developer reproduced the stall on Tailscale's gVisor pin and suggested bumping the pin once this merges (tailscale/tailscale#22083).

Fixes #15013

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, read through a new
Stack.TransportProtocolDefaultHandler getter, giving the forwarder the
same chance a listening endpoint gets.

If the default handler declines the SYN, reply with a RST, as
nic.DeliverTransportPacket does on the normal delivery path.

Only a SYN without ACK counts as a reopening SYN, matching Linux's
tcp_timewait_state_process. So a SYN-ACK with a higher sequence number
is ACKed with the old numbers, and the TIME_WAIT endpoint stays to ACK
a repeated FIN, instead of the SYN-ACK reaching the forwarder and both
getting a RST. Suggested by Tamir Duberstein in review.

Draining the rest of the TIME_WAIT queue before offering the reopening
SYN answered a queued duplicate of it with a RST, since nothing was
registered for the 4-tuple yet, and the peer's connect failed with
ECONNREFUSED. Offering the SYN first is not enough on its own, because
tcp.Forwarder records the request before its goroutine registers the
endpoint. So offer the saved SYN first, then drain the queue with the
handler that accepted it as the fallback for segments with no
registered destination; the forwarder drops the duplicate as already
in flight. A listener, or a handler that declines the SYN, keeps the
usual drain. Other close paths never call the handler while holding
their locks.

Fixes gvisor#15013

Signed-off-by: drakeo338 <[email protected]>
Co-authored-by: Tamir Duberstein <[email protected]>
Signed-off-by: Aditya Merchant <[email protected]>
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.

SYN in TIME_WAIT is dropped when the stack accepts through tcp.Forwarder

2 participants