From 8414d46bed5977fb73151e34e2badedc087c258c Mon Sep 17 00:00:00 2001 From: Maksim An Date: Sun, 12 Jul 2026 23:10:05 -0700 Subject: [PATCH] test: fix race in TestBridge_FullReconnectCycle The iteration-1 writer goroutine ranged over b.responseChan directly, so the field was read lazily when the goroutine was scheduled. If that happened after iteration 2 reassigned b.responseChan, the leftover goroutine bound to the new channel and consumed the drained "between" notification, making the test's receive time out. Capture the channel in a local variable so the goroutine is bound to iteration 1's channel regardless of later reassignment. Signed-off-by: Maksim An --- internal/guest/bridge/bridge_reconnect_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/guest/bridge/bridge_reconnect_test.go b/internal/guest/bridge/bridge_reconnect_test.go index 3042bc5ff5..b035da69fd 100644 --- a/internal/guest/bridge/bridge_reconnect_test.go +++ b/internal/guest/bridge/bridge_reconnect_test.go @@ -120,8 +120,13 @@ func TestBridge_FullReconnectCycle(t *testing.T) { b.responseChan = make(chan bridgeResponse, 4) b.quitChan = make(chan bool) + // Bind the writer goroutine to this iteration's channel explicitly. + // Ranging over b.responseChan directly reads the field lazily when the + // goroutine is scheduled, which can race with the reassignment in + // iteration 2 and let this goroutine steal the drained notification. + rc1 := b.responseChan go func() { - for range b.responseChan { + for range rc1 { } }() // drain writer