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 <shaojunyang@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: David Chase <drchase@google.com>
This commit is contained in:
Nicola Murino
2026-07-12 08:19:29 -07:00
parent e8ad5cb7aa
commit 4044611da8
+11 -1
View File
@@ -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
}