wgengine/netstack: add TS_NETSTACK_ENABLE_RACK opt-out

Since 1.104.0 (#21303), netstack's TCP uses gVisor's RACK-TLP loss
detection again. In the gVisor that go.mod pins, RACK's loss marks do
not reduce the SACK recovery pipe, and after an RTO, RACK starts fast
recovery for the same flight, with ssthresh 2 and cwnd 5. After a
burst loss, the sender can then retransmit about two segments per RTO
for seconds to tens of seconds, and for minutes when the client does
not offer TCP timestamps (Windows' default), because the RTO then
keeps backing off. That stalls TCP that netstack terminates, such as
tailscale serve, Tailscale SSH and tsnet, while kernel TCP over the
same path does not stall.

Add TS_NETSTACK_ENABLE_RACK as an explicit opt-out without changing
the default. Unset keeps gVisor's default, RACK on; true keeps it on
explicitly. Setting it to false brings back the RFC 6675 SACK loss
recovery that netstack used from 1.82 through 1.102, until go.mod has
a gVisor with the fixes (google/gvisor#15432 and google/gvisor#16081).
Keep RACK enabled by default because disabling it is several times
slower on paths that reorder packets (#20893).

Test the default, explicitly enabled, and explicitly disabled cases.

Updates #21946
Fixes #22045

Signed-off-by: Aditya Merchant <[email protected]>
Signed-off-by: James Tucker <[email protected]>
Co-authored-by: James Tucker <[email protected]>
Change-Id: I7d8012beed8a5722fb026203625299b5597fdadc
(cherry picked from commit 949adb0f6c)
This commit is contained in:
Aditya Merchant authored and James Tucker committed 2026-11-02 12:03:24 -08:00
1 parent 8a925434dc
commit 41b9ed95c0
2 files changed
+50

No files matched your search

+24
View File
@@ -138,6 +138,20 @@ var netstackKeepaliveIdle = envknob.RegisterDuration("TS_NETSTACK_KEEPALIVE_IDLE
// at the netstack default. Value is a Go duration, e.g. "15s".
var netstackKeepaliveInterval = envknob.RegisterDuration("TS_NETSTACK_KEEPALIVE_INTERVAL")
// netstackEnableRACK overrides whether netstack's TCP uses RACK-TLP loss
// detection (RFC 8985). RACK remains enabled by default; only explicitly
// setting TS_NETSTACK_ENABLE_RACK=false disables it. When false, TCP falls
// back to RFC 6675 SACK loss recovery, as netstack did from 1.82 through 1.102.
//
// Why: until go.mod has google/gvisor#15432 and google/gvisor#16081, RACK's
// loss marks do not reduce the SACK recovery pipe, and after an RTO, RACK
// starts fast recovery for the same flight with a cwnd of 5. After a burst
// loss the sender can then retransmit about two segments per RTO for seconds
// to tens of seconds (tailscale/tailscale#21946). RACK off is in turn slower
// on paths that reorder packets (tailscale/tailscale#20893), so unset keeps
// gVisor's default.
var netstackEnableRACK = envknob.RegisterOptBool("TS_NETSTACK_ENABLE_RACK")
var (
serviceIP = tsaddr.TailscaleServiceIP()
serviceIPv6 = tsaddr.TailscaleServiceIPv6()
@@ -394,6 +408,16 @@ func Create(logf logger.Logf, tundev *tstun.Wrapper, e wgengine.Engine, mc *magi
if tcpipErr != nil {
return nil, fmt.Errorf("could not set cubic congestion control: %v", tcpipErr)
}
if rack, ok := netstackEnableRACK().Get(); ok {
recovery := tcpip.TCPRecovery(0)
if rack {
recovery = tcpip.TCPRACKLossDetection
}
tcpipErr = ns.ipstack.SetTransportProtocolOption(tcp.ProtocolNumber, &recovery)
if tcpipErr != nil {
return nil, fmt.Errorf("could not set TCP loss recovery: %v", tcpipErr)
}
}
err := setTCPBufSizes(ns.ipstack)
if err != nil {
return nil, err
+26
View File
@@ -20,6 +20,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip/network/ipv4"
"gvisor.dev/gvisor/pkg/tcpip/network/ipv6"
"gvisor.dev/gvisor/pkg/tcpip/stack"
"gvisor.dev/gvisor/pkg/tcpip/transport/tcp"
"gvisor.dev/gvisor/pkg/tcpip/transport/udp"
"gvisor.dev/gvisor/pkg/waiter"
"tailscale.com/envknob"
@@ -965,6 +966,31 @@ func TestTCPForwardLimits_PerClient(t *testing.T) {
}
}
// TestEnableRACKKnob verifies that RACK remains enabled by default and that
// TS_NETSTACK_ENABLE_RACK must be explicitly false to disable it.
func TestEnableRACKKnob(t *testing.T) {
for _, tt := range []struct {
env string
want tcpip.TCPRecovery
}{
{"", tcpip.TCPRACKLossDetection},
{"false", 0},
{"true", tcpip.TCPRACKLossDetection},
} {
t.Run("TS_NETSTACK_ENABLE_RACK="+tt.env, func(t *testing.T) {
envknob.SetenvForTest(t, "TS_NETSTACK_ENABLE_RACK", tt.env)
ns := makeNetstack(t, nil)
var got tcpip.TCPRecovery
if err := ns.ipstack.TransportProtocolOption(tcp.ProtocolNumber, &got); err != nil {
t.Fatalf("TransportProtocolOption: %v", err)
}
if got != tt.want {
t.Errorf("TCP loss recovery = %v, want %v", got, tt.want)
}
})
}
}
// TestHandleLocalPackets tests the handleLocalPackets function, ensuring that
// we are properly deciding to handle packets that are destined for "local"
// IPs–addresses that are either for this node, or that it is responsible for.