Skip to content

Commit 36db10f

Browse files
author
Bryan C. Mills
committed
net: remove erroneous Dial check in TestListenerClose
TestListenerClose had been asserting that a Dial to the newly-closed address always fails, on the assumption that the listener's address and port would not be reused by some other listener that could then accept the connection. As far as I can tell, that assumption is not valid: the Dial after Close may well connect to a Listener opened for some other test, or even one opened by a completely different process running concurrently on the same machine. Fixes #38700 Change-Id: I925ed1b2ccb556135a2c5be0240d1789ed27d5fc Reviewed-on: https://go-review.googlesource.com/c/go/+/370666 Trust: Bryan Mills <[email protected]> Run-TryBot: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 9bfe09d commit 36db10f

File tree

1 file changed

+6
-23
lines changed

1 file changed

+6
-23
lines changed

src/net/net_test.go

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ func TestListenerClose(t *testing.T) {
243243
defer os.Remove(ln.Addr().String())
244244
}
245245

246-
dst := ln.Addr().String()
247246
if err := ln.Close(); err != nil {
248247
if perr := parseCloseError(err, false); perr != nil {
249248
t.Error(perr)
@@ -256,28 +255,12 @@ func TestListenerClose(t *testing.T) {
256255
t.Fatal("should fail")
257256
}
258257

259-
if network == "tcp" {
260-
// We will have two TCP FSMs inside the
261-
// kernel here. There's no guarantee that a
262-
// signal comes from the far end FSM will be
263-
// delivered immediately to the near end FSM,
264-
// especially on the platforms that allow
265-
// multiple consumer threads to pull pending
266-
// established connections at the same time by
267-
// enabling SO_REUSEPORT option such as Linux,
268-
// DragonFly BSD. So we need to give some time
269-
// quantum to the kernel.
270-
//
271-
// Note that net.inet.tcp.reuseport_ext=1 by
272-
// default on DragonFly BSD.
273-
time.Sleep(time.Millisecond)
274-
275-
cc, err := Dial("tcp", dst)
276-
if err == nil {
277-
t.Error("Dial to closed TCP listener succeeded.")
278-
cc.Close()
279-
}
280-
}
258+
// Note: we cannot ensure that a subsequent Dial does not succeed, because
259+
// we do not in general have any guarantee that ln.Addr is not immediately
260+
// reused. (TCP sockets enter a TIME_WAIT state when closed, but that only
261+
// applies to existing connections for the port — it does not prevent the
262+
// port itself from being used for entirely new connections in the
263+
// meantime.)
281264
})
282265
}
283266
}

0 commit comments

Comments
 (0)