mirror of https://github.com/golang/go.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 <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>
This commit is contained in:
parent
a742ae493f
commit
2e7e1d2e8d
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue