From 82adefa711cb8d9a1f12c7ea91b491007d21819f Mon Sep 17 00:00:00 2001 From: Daniel McCarney Date: Tue, 18 Aug 2026 13:38:51 -0400 Subject: [PATCH] ssh: synchronize unexpected response test Wait for an ordered channel request after sending the unsolicited response flood. This ensures that the client mux has discarded the entire flood before SendRequest opens its response gate, avoiding confusion between an in-flight unsolicited response and the expected reply. This fixes TestChannelUnexpectedResponsesDiscarded from flaking, where otherwise running 1000000 iterations of the test with GOMAXPROCS=16 produced ~15 distinct failures of the form "expected success reply". Change-Id: Ic1125c1f44bd919a5cf32b889d331bbc94c06c25 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/817140 Reviewed-by: Neal Patel LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com Reviewed-by: Neal Patel Reviewed-by: Nicola Murino Auto-Submit: Daniel McCarney Reviewed-by: David Chase --- ssh/mux_test.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ssh/mux_test.go b/ssh/mux_test.go index 4996878..6e3890b 100644 --- a/ssh/mux_test.go +++ b/ssh/mux_test.go @@ -1181,6 +1181,13 @@ func TestChannelUnexpectedResponsesDiscarded(t *testing.T) { return } } + // Follow the flood with a request so the client can synchronize with + // its mux loop. Once the client receives this request, the mux loop has + // necessarily processed (and discarded) all the preceding responses. + if _, err := serverCh.SendRequest("sync", false, nil); err != nil { + done <- fmt.Errorf("send sync request: %w", err) + return + } // Echo any legitimate request back. for req := range serverCh.incomingRequests { if req.WantReply { @@ -1193,9 +1200,17 @@ func TestChannelUnexpectedResponsesDiscarded(t *testing.T) { done <- nil }() + req, ok := <-clientCh.incomingRequests + if !ok { + t.Fatal("channel closed before sync request") + } + if req.Type != "sync" { + t.Fatalf("unexpected sync request type %q", req.Type) + } + // If the flood had wedged the mux loop, this SendRequest would never // receive a reply. - ok, err := clientCh.SendRequest("ping", true, []byte("hello")) + ok, err = clientCh.SendRequest("ping", true, []byte("hello")) if err != nil { t.Fatalf("SendRequest: %v", err) }