• Daniel Martí's avatar
    net: fix data race in TestClosingListener · 0e4de78d
    Daniel Martí authored
    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í <mvdan@mvdan.cc>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
    0e4de78d
listen_test.go 20 KB