Files
Brad Fitzpatrick af9bfa07c3 net/tstun, feature/conn25: make app connector hooks safe to set while running
feature/conn25 installs its tstun.Wrapper hooks from its ipnext
extension's Init, which runs from LocalBackend.Start. By then the
wireguard-go device's RoutineReadFromTUN goroutine is already reading
packets and calling filterPacketOutboundToWireGuard, which read the
plain PreFilterPacketOutboundToWireGuardAppConnectorIntercept field
with no synchronization. A packet from the OS TUN in that window was a
data race; under -race, tailscaled in tstest/integration died with
"WARNING: DATA RACE" (conn25.go installHooks write vs wrap.go:797
read), and the test then failed with "running tailscale status: ...
EOF". All six CI logs examined show this same race.

Make the three hooks conn25 sets after startup
(PreFilterPacketOutboundToWireGuardAppConnectorIntercept,
PostFilterPacketInboundFromWireGuardAppConnector and
OnUnmappedTransitIPMessage) syncs.AtomicValues.

Add TestSetAppConnectorHooksWhileRunning, which installs the hooks
while packets flow in both directions and reproduces the CI race at
the same wrap.go line.

flakestress -race TestSetAppConnectorHooksWhileRunning:
before: 12564/12564 runs failed; after: 0/1176 runs.

The integration flake was too rare to measure locally (a few failures a
week in CI). It was blamed on tstest/integration TestTUNMode,
TestMagicDNS and TestSplitDNS.

Fixes #22557

Change-Id: Iff618c18c11f84dcbae27805024e908403031a08
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-22 16:46:06 -08:00
..