tailscale/wgengine/netstack
Brad Fitzpatrick 50b8cfbde2 wgengine/netstack: fix data race on in-flight connection test globals
The maxInFlightConnectionAttemptsForTest and
maxInFlightConnectionAttemptsPerClientForTest globals were plain ints
read by background gVisor TCP handler goroutines (via
wrapTCPProtocolHandler) and written by tstest.Replace cleanup in
TestTCPForwardLimits_PerClient. When a gVisor goroutine outlived the
test cleanup window, the race detector caught the unsynchronized
access.

The race-prone code was introduced in c5abbcd4b4 (2024-02-26,
"wgengine/netstack: add a per-client limit for in-flight TCP
forwards") which added both the plain int globals and the
TestTCPForwardLimits_PerClient test that writes them via
tstest.Replace. It is not obvious why this has only recently started
being detected as a data race; likely some combination of gVisor
version bumps, Go toolchain scheduler changes, and additional
TCP-injecting subtests (e.g. 03461ea7f, 2026-01-30) increased
goroutine churn enough to hit the window.

Change both globals to atomic.Int32 and replace tstest.Replace (which
does non-atomic *target = old on cleanup) with explicit Store/Cleanup
pairs.

Fixes #19118

Change-Id: Id26ba6fbfb2e4ade319976db80af8e16c7c8778e
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2026-04-13 15:24:35 -07:00
..
gro all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
link_endpoint.go wgengine/netstack: deliver self-addressed packets via loopback 2026-02-27 14:30:41 -08:00
netstack_linux.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netstack_tcpbuf_default.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netstack_tcpbuf_ios.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netstack_test.go wgengine/netstack: fix data race on in-flight connection test globals 2026-04-13 15:24:35 -07:00
netstack_userping_apple.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netstack_userping_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netstack_userping.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
netstack.go wgengine/netstack: fix data race on in-flight connection test globals 2026-04-13 15:24:35 -07:00