Files
tailscale/ssh
Brad Fitzpatrick 940e4c2c67 ssh/tailssh: write watchdog test PID markers atomically
TestMonitorCloseWatchdogForwardChild occasionally failed on Linux CI
with `invalid helper PID marker ".../forward-pid": ""`.

The re-exec'd helper wrote its PID marker with os.WriteFile, which
creates (and truncates) the file before writing the contents. The test
polls for the marker every 20ms and treats any successful read as
final, so a poll landing between the create and the write saw an empty
file and failed. This is a test-only race; the monitor itself was
fine.

Write the marker to a temp file and rename it into place, so the poll
sees either no file or the full PID.

The natural rate is too low to measure locally (0/168 runs of the
~14s-under-race test in 5m with flakestress -race -p 8 -taskset 0-3),
so the window was widened by injecting a 100ms sleep:
before (sleep between create and write): 3/3 runs failed with the
CI error.
after (sleep between write and rename): 0/3 runs failed.
after, without injection, flakestress -race -p 4, 5m: 0/84 runs.

Fixes #22559

Change-Id: I855d18f006535140bc136ee876b311212f8884b6
Signed-off-by: Brad Fitzpatrick <[email protected]>
2026-11-23 08:54:18 -08:00
..