From 4044611da8b85cbd5eb55c657d59244ffb18d3e4 Mon Sep 17 00:00:00 2001 From: Nicola Murino Date: Sun, 5 Jul 2026 20:14:11 +0200 Subject: [PATCH] ssh: fix data race in the doClientServerAuth test helper The helper returned the auth errors collected via AuthLogCallback without waiting for the server goroutine that appends to them. Close the client side of the connection on handshake failure, to unblock a server still reading from it, and join the server goroutine before returning. Change-Id: Ibe8c3b236491769f3433f7457d4f2b9a07a65be0 Reviewed-on: https://go-review.googlesource.com/c/crypto/+/797043 Reviewed-by: Junyang Shao LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com Reviewed-by: Filippo Valsorda Reviewed-by: David Chase --- ssh/server_multi_auth_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ssh/server_multi_auth_test.go b/ssh/server_multi_auth_test.go index 3b39802..529d6bf 100644 --- a/ssh/server_multi_auth_test.go +++ b/ssh/server_multi_auth_test.go @@ -26,11 +26,21 @@ func doClientServerAuth(t *testing.T, serverConfig *ServerConfig, clientConfig * serverConfig.AuthLogCallback = func(conn ConnMetadata, method string, err error) { serverAuthErrors = append(serverAuthErrors, err) } - go newServer(c1, serverConfig) + serverDone := make(chan struct{}) + go func() { + defer close(serverDone) + newServer(c1, serverConfig) + }() c, _, _, err := NewClientConn(c2, "", clientConfig) if err == nil { c.Close() + } else { + // Unblock the server if it is still reading from the connection. + c2.Close() } + // Wait for the server side to finish before reading serverAuthErrors: + // AuthLogCallback appends to it from the server goroutine. + <-serverDone return serverAuthErrors, err }