Skip to content

Commit 0e4de78

Browse files
committed
net: fix data race in TestClosingListener
In https://golang.org/cl/66334, the test was changed so that the second Listen would also be closed. However, it shouldn't have reused the same ln variable, as that can lead to a data race with the background loop that accepts connections. Simply define a new Listener, since we don't need to overwrite the first variable. I was able to reproduce the data race report locally about 10% of the time by reducing the sleep from a millisecond to a nanosecond. After the fix, it's entirely gone after 1000 runs. Fixes #22226. Change-Id: I7c639f9f2ee5098eac951a45f42f97758654eacd Reviewed-on: https://go-review.googlesource.com/70230 Run-TryBot: Daniel Martí <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 743117a commit 0e4de78

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/net/listen_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,9 +723,9 @@ func TestClosingListener(t *testing.T) {
723723

724724
ln.Close()
725725

726-
ln, err = Listen("tcp", addr.String())
726+
ln2, err := Listen("tcp", addr.String())
727727
if err != nil {
728728
t.Fatal(err)
729729
}
730-
ln.Close()
730+
ln2.Close()
731731
}

0 commit comments

Comments
 (0)