Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5fbfd7

Browse files
authored
fix: fix hang in teardown of TestConn_CoordinatorRollingRestart (#15624)
fixes a flake seen on main: https://github.com/coder/coder/actions/runs/11967210463/job/33364072261 the TCP echo server had a waitgroup to ensure that all accepted connections get torn down, but no explicit teardown of the connection. We depended on the tailnet agent closing its side of the connection, which depends on closing the tunneled connection. The tunneled `FIN` could race with tearing down the tunnel itself. So, this PR adds explicit `t.Cleanup` to close the echo connection. It also removes the waitgroup. The purpose of the waitgroup was to ensure that all goroutines created by the echo listener get shut down, but we have `goleak` for that, which fails much faster than the 20 minutes this test run took.
1 parent 103824f commit b5fbfd7

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

enterprise/coderd/coderd_test.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -852,30 +852,26 @@ func TestConn_CoordinatorRollingRestart(t *testing.T) {
852852
}
853853

854854
func tcpEchoServer(t *testing.T) string {
855-
var listenerWg sync.WaitGroup
856855
tcpListener, err := net.Listen("tcp", "127.0.0.1:0")
857856
require.NoError(t, err)
858857
t.Cleanup(func() {
859858
_ = tcpListener.Close()
860-
listenerWg.Wait()
861859
})
862-
listenerWg.Add(1)
863860
go func() {
864-
defer listenerWg.Done()
865861
for {
866862
conn, err := tcpListener.Accept()
867863
if err != nil {
868864
return
869865
}
870-
listenerWg.Add(1)
866+
t.Cleanup(func() {
867+
_ = conn.Close()
868+
})
871869
go func() {
872-
defer listenerWg.Done()
873870
defer conn.Close()
874871
_, _ = io.Copy(conn, conn)
875872
}()
876873
}
877874
}()
878-
879875
return tcpListener.Addr().String()
880876
}
881877

0 commit comments

Comments
 (0)