]> Cypherpunks.ru repositories - gostls13.git/commitdiff
net: synchronize calls to Close in the withTCPConnPair test helper
authorBryan C. Mills <bcmills@google.com>
Fri, 8 Sep 2023 20:39:17 +0000 (16:39 -0400)
committerGopher Robot <gobot@golang.org>
Fri, 8 Sep 2023 20:56:46 +0000 (20:56 +0000)
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 <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Commit-Queue: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/net/net_test.go

index a0ac85f406799df6c4161c28fa8452c7b46bad10..38ed31e0f1950792de59833bc0f5d130fb7cd9a8 100644 (file)
@@ -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)
                }
        }
 }