From: Bryan C. Mills Date: Fri, 8 Sep 2023 20:39:17 +0000 (-0400) Subject: net: synchronize calls to Close in the withTCPConnPair test helper X-Git-Tag: go1.22rc1~926 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=2e7e1d2e8d96ddf2aff00feb645cfa94bc9e4786;p=gostls13.git net: synchronize calls to Close in the withTCPConnPair test helper withTCPConnPair is supposed to return only when both peer functions have completed. However, due to the use of "defer" it was closing the peers' connections after the synchronization point instead of before. Fixes #62542. Change-Id: I3e06c78984664172ff2d28b0fc582b8182f710f9 Reviewed-on: https://go-review.googlesource.com/c/go/+/526977 Auto-Submit: Bryan Mills Run-TryBot: Bryan Mills TryBot-Result: Gopher Robot Commit-Queue: Bryan Mills Reviewed-by: Ian Lance Taylor --- diff --git a/src/net/net_test.go b/src/net/net_test.go index a0ac85f406..38ed31e0f1 100644 --- a/src/net/net_test.go +++ b/src/net/net_test.go @@ -440,8 +440,9 @@ func withTCPConnPair(t *testing.T, peer1, peer2 func(c *TCPConn) error) { errc <- err return } - defer c1.Close() - errc <- peer1(c1.(*TCPConn)) + err = peer1(c1.(*TCPConn)) + c1.Close() + errc <- err }() go func() { c2, err := Dial("tcp", ln.Addr().String()) @@ -449,12 +450,13 @@ func withTCPConnPair(t *testing.T, peer1, peer2 func(c *TCPConn) error) { errc <- err return } - defer c2.Close() - errc <- peer2(c2.(*TCPConn)) + err = peer2(c2.(*TCPConn)) + c2.Close() + errc <- err }() for i := 0; i < 2; i++ { if err := <-errc; err != nil { - t.Fatal(err) + t.Error(err) } } }