Skip to content

netstack: a SYN reusing a 4-tuple held in TIME_WAIT is silently dropped for 60s (tailscale serve, forwarder has no listener) #22083

Open

Description

@nestery

What is the issue?

When tailscaled serves TCP from its own netstack (here tailscale serve --https=443 on a node in userspace-networking mode), and the netstack side closes a connection first, gVisor keeps that 4-tuple in TIME_WAIT for DefaultTCPTimeWaitTimeout, 60 seconds.
If the client picks the same source port again within that minute, every SYN of the new connection is dropped: no SYN-ACK and no RST.
The client's kernel has long since freed the port, so Linux reusing it is legitimate.
The client sees a connect that hangs until its own timeout, while the peer is online and its WireGuard traffic keeps arriving.

Expected: the new connection is accepted, as a Linux kernel TCP server in TIME_WAIT accepts a SYN with a higher sequence number (RFC 1122 4.2.2.13), or at least answered with a reset so the client fails fast.

Why it happens, from reading the code (tailscale main, gVisor at the pinned a6f909f08a72):

  • receiver.handleTimeWaitSegment (pkg/tcpip/transport/tcp/rcv.go) drops RSTs, returns newSyn for a SYN whose sequence number is above RcvNxt, and drops any other segment that has no ACK.
  • Endpoint.handleTimeWaitSegments (pkg/tcpip/transport/tcp/connect.go) hands a newSyn segment on only when FindTransportEndpoint finds an endpoint in StateListen for the local address and port.
  • wgengine/netstack/netstack.go accepts TCP through tcp.NewForwarder, not a listening endpoint, so there is never one to find, and the SYN is dropped.
  • tailscaled does not set tcpip.TCPTimeWaitTimeoutOption, and offers no knob for it (only TS_NETSTACK_KEEPALIVE_IDLE and TS_NETSTACK_KEEPALIVE_INTERVAL).

In our case it surfaced as docker login against a registry behind tailscale serve timing out after 15 seconds, once in about two weeks of CI pushes:

Error response from daemon: Get "https://<registry>.ts.net/v2/": context deadline exceeded (Client.Timeout exceeded while awaiting headers)

The client node's tailscaled logged, during that login:

open-conn-track: timeout opening (TCP <client>:58775 => <server>:443) to node [xxxxx]; online=yes, lastRecv=13s
open-conn-track: timeout opening (TCP <client>:58775 => <server>:443) to node [xxxxx]; online=yes, lastRecv=2s
open-conn-track: timeout opening (TCP <client>:58775 => <server>:443) to node [xxxxx]; online=yes, lastRecv=8s
open-conn-track: timeout opening (TCP <client>:58775 => <server>:443) to node [xxxxx]; online=yes, lastRecv=2s

The server node logged nothing for it, and the HTTP server behind serve saw no request.

Steps to reproduce

Server node: tailscaled in userspace-networking mode, with tailscale serve --https=443 in front of a local HTTP server.
Client node: any Linux node on the same tailnet.

  1. From the client, bind a fixed source port, open a TLS connection to the server node's tailnet address on 443, send an HTTP/1.1 request with Connection: close, read the response to EOF, and close without sending TLS close_notify.
    The server side closes first, so the server's netstack holds the 4-tuple in TIME_WAIT.
  2. Within 60 seconds, bind the same source port again and connect to the same address and port.

Observed: the second connect took 69.2 seconds (the SYN retransmits until the TIME_WAIT expired), and the client's tailscaled logged the same open-conn-track: timeout opening ... online=yes lines for that port.

Control: when the client sends close_notify before closing, the server answers with a reset rather than entering TIME_WAIT, and the next connect from the same port succeeds at once.

Are there any recent changes that introduced the issue?

Not that we know of. The TIME_WAIT path and the forwarder look unchanged on main.

Possible fixes:

  • Let a valid TIME_WAIT-reusing SYN reach the stack's forwarder when no listening endpoint exists, as Linux accepts it for a listener (this may be a gVisor change).
  • Or set tcpip.TCPTimeWaitTimeoutOption on tailscaled's stack, with a shorter default or a TS_NETSTACK_* knob beside the keepalive ones.

OS

Linux

OS version

Ubuntu 24.04.4 LTS under WSL2 (Windows build 10.0.26300), kernel 6.18.54.1-microsoft-standard-WSL2, on both nodes

Tailscale version

1.104.2 on both nodes

Other software

Docker 29.9.1 as the client; zot as the HTTP server behind tailscale serve.

Bug report

Not attached.

Activity

  1. adios-404 commented on Oct 31, 2026

    @adios-404
    Contributor

    Thanks for the detailed report. This matches gvisor/gvisor#15013 in gVisor's netstack, and gvisor/gvisor#15019 is the pending fix (open since Sep 25, not reviewed yet).

    Your reading of the code is right: on 1.104.2 every serve connection from a peer goes through that forwarder (netstack.go#L643-L645). TUN mode would not avoid it, because netstack still takes the serve, SSH and peerAPI ports there (netstack.go#L1261-L1281).

    The PR's non-test diff applies cleanly to 1.104's gVisor pin. I tested two gVisor stacks in one process, with a forwarder-only server that closes first:

    gVisor Reconnect from the same port Dials stalled at 300/s, after the first minute
    a6f909f08a72 (1.104 pin) 63.0 s 28.4% (1,108 of 3,897)
    a6f909f08a72 + gvisor/gvisor#15019 at once 0 of 3,868

    A shorter TIME_WAIT helps but does not fix it: with a 1 s TCPTimeWaitTimeoutOption, stalls still happened in daaain's Lima tests, each about 1 s (the client's first SYN retransmission).

    Where you control the client, closing with SO_LINGER 0 avoided it in reports on both gVisor threads: as in your close_notify control, netstack then keeps no TIME_WAIT.

  2. added
    services
    on Nov 2, 2026
  3. added theissue type on Nov 2, 2026
  4. bcreane commented on Nov 12, 2026

    @bcreane
    Contributor

    Thanks for the thorough report, and thanks @adios-404 for the measurements.

    I was able to reproduce this against the gVisor commit we currently pin, using a forwarder-only server that closes first. A reconnect from the same source port stalls until TIME_WAIT expires, and with the non-test part of gvisor/gvisor#15019 applied the same reconnect goes through immediately. Shortening the TIME_WAIT timeout on our side would only reduce the stall to about a second, since the client's first SYN retransmission still has to wait, so it doesn't look like a real fix.

    The right fix appears to be the upstream gVisor change. cc @raggi, you've been handling our gVisor updates - I think we need to track gvisor/gvisor#15019 and bump our commit once it merges.

  5. Ramblurr commented on Nov 23, 2026

    @Ramblurr

    Same bug on the subnet-route / exit-node forwarding path, with stock tailscaled 1.104.6 in --tun=userspace-networking and nothing in front. A advertises 192.168.2.0/24, where C runs nginx with its default config. From client B:

    sudo sysctl -w net.ipv4.ip_local_port_range="50000 50099"
    ab -n 30 -c 1 -s 130 http://192.168.2.3/   # ApacheBench, https://httpd.apache.org/docs/2.4/programs/ab.html

    ab reports a Connect max of about 68000 ms. On B's tailscale0 there's a SYN on the same port 28 ms after the server-closed flow, 10 retransmits, and a SYN-ACK 68.4 s later. In kernel TUN mode the same commands show no stall.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugservices

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions