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>
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 @@ 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 }