From f1b588d29fa2d5b129382423103dedaf0dc50c93 Mon Sep 17 00:00:00 2001 From: Steven van der Vegt Date: Mon, 27 Jul 2026 18:37:40 +0200 Subject: [PATCH] test(network): fix flaky Test_conn_startSending The test cancelled the stream before calling disconnect(), racing the receive goroutine (which stores the stream error as close status) against disconnect() cancelling the connection context. Disconnecting first guarantees the context is cancelled before RecvMsg returns, so the receive loop deterministically takes the drop-message path. Master removed this test entirely (#2618); this keeps the goroutine-exit and no-panic coverage instead. Verified with -race -count=100. Assisted-by: AI --- network/transport/grpc/connection_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/network/transport/grpc/connection_test.go b/network/transport/grpc/connection_test.go index 5b4a6e2cec..1ca7652176 100644 --- a/network/transport/grpc/connection_test.go +++ b/network/transport/grpc/connection_test.go @@ -116,14 +116,17 @@ func Test_conn_startSending(t *testing.T) { assert.Equal(t, int32(2), connection.activeGoroutines) // startSending and startReceiving - stream.cancelFunc() + // Disconnect before cancelling the stream: this guarantees the connection context is + // cancelled before RecvMsg returns, so the receive loop drops the message instead of + // racing to store the stream error as close status. connection.disconnect() + stream.cancelFunc() test.WaitFor(t, func() (bool, error) { return atomic.LoadInt32(&connection.activeGoroutines) == 0, nil }, 5*time.Second, "waiting for all goroutines to exit") - // Last received message is dropped and no status is set. Default value is OK. + // A deliberate local disconnect must not record a close error. Default value is OK. assert.Equal(t, codes.OK, connection.status.Load().Code()) }) }