From 14b4650d6c20e7b18c9c9086e6d5db2fa0e8bb96 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 30 Jan 2026 15:46:38 +0000 Subject: [PATCH] chore: fix flakiness in TestSSH/StdioExitOnParentDeath (#21792) Relates to https://github.com/coder/internal/issues/1289 --- cli/ssh_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/ssh_test.go b/cli/ssh_test.go index fbf01bafbf..5167a2d8c3 100644 --- a/cli/ssh_test.go +++ b/cli/ssh_test.go @@ -1188,7 +1188,17 @@ func TestSSH(t *testing.T) { } close(sessionStarted) <-sleepDone - assert.NoError(t, session.Close()) + // Ref: https://github.com/coder/internal/issues/1289 + // This may return either a nil error or io.EOF. + // There is an inherent race here: + // 1. Sleep process is killed -> sleepDone is closed. + // 2. watchParentContext detects parent death, cancels context, + // causing SSH session teardown. + // 3. We receive from sleepDone and attempt to call session.Close() + // Now either: + // a. Session teardown completes before we call Close(), resulting in io.EOF + // b. We call Close() first, resulting in a nil error. + _ = session.Close() }() // Wait for our "parent" process to start