From 0e4de78d132677268d307f307c33831e17703195 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Daniel=20Mart=C3=AD?= Date: Thu, 12 Oct 2017 11:57:36 +0100 Subject: [PATCH] net: fix data race in TestClosingListener MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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í TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/listen_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/net/listen_test.go b/src/net/listen_test.go index c15b6bdc8f..96624f98ce 100644 --- a/src/net/listen_test.go +++ b/src/net/listen_test.go @@ -723,9 +723,9 @@ func TestClosingListener(t *testing.T) { ln.Close() - ln, err = Listen("tcp", addr.String()) + ln2, err := Listen("tcp", addr.String()) if err != nil { t.Fatal(err) } - ln.Close() + ln2.Close() } -- 2.48.1