Skip to content

Commit 6e7aee5

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
net: delete TestListenCloseListen
In CL 557177, I attempted to fix a logical race in this test (#65175). However, I introduced a data race in the process (#65209). The race was reported on the windows-amd64-race builder. When I tried to reproduce it on linux/amd64, I added a time.Sleep in the Accept loop. However, that Sleep causes the test to fail outright with EADDRINUSE, which suggests that my earlier guess about the open Conn preventing reuse of the port was, in fact, incorrect. On some platforms we could instead use SO_REUSEPORT and avoid closing the first Listener entirely, but that wouldn't be even remotely in the spirit of the original test. Since I don't see a way to preserve the test in a way that is not inherently flaky / racy, I suggest that we just delete it. It was originally added as a regression test for a bug in the nacl port, which no longer exists anyway. (Some of that code may live on in the wasm port, but it doesn't seem worth maintaining a flaky port-independent test to maintain a regression test for a bug specific to secondary platforms.) Fixes #65209. Updates #65175. Change-Id: I32f9da779d24f2e133571f0971ec460cebe7820a Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-race Reviewed-on: https://go-review.googlesource.com/c/go/+/557536 Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent e5eeadb commit 6e7aee5

File tree

1 file changed

+0
-70
lines changed

1 file changed

+0
-70
lines changed

src/net/net_test.go

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"net/internal/socktest"
1212
"os"
1313
"runtime"
14-
"sync"
1514
"testing"
1615
"time"
1716
)
@@ -294,75 +293,6 @@ func TestPacketConnClose(t *testing.T) {
294293
}
295294
}
296295

297-
func TestListenCloseListen(t *testing.T) {
298-
if testing.Short() {
299-
t.Parallel()
300-
}
301-
302-
ln := newLocalListener(t, "tcp")
303-
addr := ln.Addr().String()
304-
305-
var wg sync.WaitGroup
306-
wg.Add(1)
307-
go func() {
308-
for {
309-
c, err := ln.Accept()
310-
if err != nil {
311-
wg.Done()
312-
return
313-
}
314-
wg.Add(1)
315-
go func() {
316-
io.Copy(io.Discard, c)
317-
c.Close()
318-
wg.Done()
319-
}()
320-
}
321-
}()
322-
defer wg.Wait()
323-
324-
// Keep a connection alive while we close the listener to try to discourage
325-
// the kernel from reusing the listener's port for some other process.
326-
//
327-
// TODO(bcmills): This empirically seems to work, and we also rely on it in
328-
// TestDialClosedPortFailFast, but I can't find a reference documenting this
329-
// port-reuse behavior.
330-
c, err := Dial("tcp", addr)
331-
defer c.Close()
332-
333-
if err := ln.Close(); err != nil {
334-
if perr := parseCloseError(err, false); perr != nil {
335-
t.Error(perr)
336-
}
337-
t.Fatal(err)
338-
}
339-
340-
if !testing.Short() {
341-
// Burn through some ephemeral ports (without actually accepting any
342-
// connections on them) to try to encourage the kernel to reuse the address
343-
// if it is going to.
344-
lns := make(chan []Listener, 1)
345-
lns <- nil
346-
for i := 0; i < 4000; i++ {
347-
ln := newLocalListener(t, "tcp")
348-
lns <- append(<-lns, ln)
349-
}
350-
defer func() {
351-
for _, ln := range <-lns {
352-
ln.Close()
353-
}
354-
}()
355-
}
356-
357-
ln, err = Listen("tcp", addr)
358-
if err == nil {
359-
// Success. (This test didn't always make it here earlier.)
360-
ln.Close()
361-
return
362-
}
363-
t.Fatalf("failed to listen/close/listen on same address")
364-
}
365-
366296
// See golang.org/issue/6163, golang.org/issue/6987.
367297
func TestAcceptIgnoreAbortedConnRequest(t *testing.T) {
368298
switch runtime.GOOS {

0 commit comments

Comments
 (0)