From 4dbb3a236cb7a02e72d55dfe72587eba27df5814 Mon Sep 17 00:00:00 2001 From: Ethan <39577870+ethanndickson@users.noreply.github.com> Date: Tue, 4 Aug 2026 01:03:30 +1000 Subject: [PATCH] test: fix tailnet connection teardown flake (#27768) Closes https://github.com/coder/internal/issues/1620 Closes ENG-3043 The callback cleanup added in #20687 stops new node callbacks, but it can still race with one that's already in flight. That callback may call `UpdatePeers` after the destination `tailnet.Conn` closes, so the test fails with `connection closed` even though the redirect behaviour is correct. To fix, we'll just ignore `tailnet.ErrConnClosed` in the asynchronous `stitch` helpers, whilst continuing to assert on every other error. --- codersdk/workspacesdk/agentconn_test.go | 4 +++- tailnet/conn_test.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/codersdk/workspacesdk/agentconn_test.go b/codersdk/workspacesdk/agentconn_test.go index c77cbae3ce..a2cce9d5cd 100644 --- a/codersdk/workspacesdk/agentconn_test.go +++ b/codersdk/workspacesdk/agentconn_test.go @@ -243,7 +243,9 @@ func stitchTailnet(t *testing.T, conns map[uuid.UUID]*tailnet.Conn) { Node: protoNode, Kind: proto.CoordinateResponse_PeerUpdate_NODE, }}) - assert.NoError(t, err) + if err != nil && !errors.Is(err, tailnet.ErrConnClosed) { + assert.NoError(t, err) + } } } diff --git a/tailnet/conn_test.go b/tailnet/conn_test.go index 7e8ac53474..b2c9cd575e 100644 --- a/tailnet/conn_test.go +++ b/tailnet/conn_test.go @@ -2,6 +2,7 @@ package tailnet_test import ( "context" + "errors" "net" "net/netip" "strings" @@ -483,7 +484,9 @@ func stitch(t *testing.T, dst, src *tailnet.Conn) { Node: pn, Kind: proto.CoordinateResponse_PeerUpdate_NODE, }}) - assert.NoError(t, err) + if err != nil && !errors.Is(err, tailnet.ErrConnClosed) { + assert.NoError(t, err) + } }) // ensures we don't send callbacks after the test ends and connections are closed. t.Cleanup(func() {