From d3a44a2a6b7df7dd941d40929be284dd1fb6dbc5 Mon Sep 17 00:00:00 2001 From: zhangwenjian Date: Sat, 5 Sep 2026 16:42:47 +0800 Subject: [PATCH] =?UTF-8?q?test=E2=9C=85:=20dial=20the=20stalling=20connec?= =?UTF-8?q?tion=20after=20the=20signal,=20not=20at=20start-up?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit net/http stops counting a StateNew connection against Shutdown once it is more than five seconds old. The connection was opened when the child started and the parent then waited for readiness before signalling, so on a slow run the connection could age past that mark and Shutdown would succeed - and the test would fail on its own "this proves nothing" guard rather than on the behaviour it is there to pin. Opening it immediately before the shutdown keeps the timeout deterministic. Claude-Session: https://claude.ai/code/session_01HPTAw8b8tAdFNFn8rKdPYx --- cmd/api/signal_test.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/cmd/api/signal_test.go b/cmd/api/signal_test.go index 9d0f6a3f..09c74c25 100644 --- a/cmd/api/signal_test.go +++ b/cmd/api/signal_test.go @@ -44,15 +44,6 @@ func TestSignalChild(t *testing.T) { srv := &http.Server{Handler: http.NewServeMux()} go func() { _ = srv.Serve(ln) }() - if os.Getenv(childHangConn) == "1" { - c, err := net.Dial("tcp", ln.Addr().String()) - if err != nil { - fmt.Println("dial:", err) - os.Exit(5) - } - defer func() { _ = c.Close() }() - } - // Arm before announcing readiness. Doing it the other way round leaves a // window in which the parent's signal reaches the default handler and // kills the child before any of this runs - which is exactly the failure @@ -77,6 +68,16 @@ func TestSignalChild(t *testing.T) { timeout := shutdownTimeout if os.Getenv(childHangConn) == "1" { + // Dialled here, not at start-up. net/http stops counting a StateNew + // connection against Shutdown once it is more than five seconds old, + // so a connection opened before the wait would age out on a slow CI + // run and Shutdown would succeed - leaving the test asserting nothing. + c, err := net.Dial("tcp", ln.Addr().String()) + if err != nil { + fmt.Println("dial:", err) + os.Exit(5) + } + defer func() { _ = c.Close() }() // A connection that has sent nothing keeps Shutdown busy: net/http // only treats a StateNew connection as idle once it is more than five