tailscale/ssh/tailssh
Brad Fitzpatrick 2b1cfa7c4d ssh/tailssh: fix race in session termination message delivery
When a recording upload fails mid-session, the recording goroutine
cancels the session context. This triggers two concurrent paths:
exec.CommandContext kills the process (causing cmd.Wait to return),
and killProcessOnContextDone tries to write the termination message
via exitOnce.Do. If cmd.Wait returns first, the main goroutine's
exitOnce.Do(func(){}) steals the once, and the termination message
is never written to the client.

Fix by waiting for killProcessOnContextDone to finish writing the
termination message (via <-ss.exitHandled) before claiming exitOnce,
when the context is already done.

Also fix the fallback path when launchProcess itself fails due to
context cancellation: use SSHTerminationMessage() with the correct
"\r\n\r\n" framing instead of fmt.Fprintf with the internal error
string.

Deflakes TestSSHRecordingCancelsSessionsOnUploadFailure, which was
failing consistently at a low rate due to the exitOnce race. After
this fix, flakestress passes with 8,668 runs, 0 failures.

Fixes #7707 (again. hopefully for good.)

Change-Id: I5ab911c71574db8d3f9d979fb839f273be51ecf9
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2026-04-07 05:31:16 -07:00
..
testcontainers ssh: replace tempfork with tailscale/gliderssh 2026-04-07 11:59:38 +01:00
accept_env_test.go cmd/vet: add subtestnames analyzer; fix all existing violations 2026-04-05 15:52:51 -07:00
accept_env.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
auditd_linux_test.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
auditd_linux.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
c2n.go ipn/ipnlocal, feature/ssh: move SSH code out of LocalBackend to feature 2026-03-10 17:27:17 -07:00
hostkeys_test.go ipn/ipnlocal, feature/ssh: move SSH code out of LocalBackend to feature 2026-03-10 17:27:17 -07:00
hostkeys.go ssh: replace tempfork with tailscale/gliderssh 2026-04-07 11:59:38 +01:00
incubator_linux.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
incubator_plan9.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
incubator.go ssh: replace tempfork with tailscale/gliderssh 2026-04-07 11:59:38 +01:00
privs_test.go all: use Go 1.26 things, run most gofix modernizers 2026-03-06 13:32:03 -08:00
tailssh_integration_test.go ssh: replace tempfork with tailscale/gliderssh 2026-04-07 11:59:38 +01:00
tailssh_test.go ssh/tailssh: fix race in session termination message delivery 2026-04-07 05:31:16 -07:00
tailssh.go ssh/tailssh: fix race in session termination message delivery 2026-04-07 05:31:16 -07:00
user.go all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00