]> Cypherpunks repositories - gostls13.git/commit
net/http: avoid making a request to a closed server in TestServerShutdown
authorBryan C. Mills <bcmills@google.com>
Mon, 13 Mar 2023 21:36:36 +0000 (17:36 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 15 Mar 2023 17:40:40 +0000 (17:40 +0000)
commit2a30b34e293b6308dd1304dfedc96e0a7858476f
tree5db7f59d6a2a1f874c7c3b48d2390b115263338d
parentf26bf203ac67fd917f2eb992baa1cb2d01edf3c8
net/http: avoid making a request to a closed server in TestServerShutdown

As soon as the test server closes its listener, its port may be reused
for another test server. On some platforms port reuse takes a long
time, because they cycle through the available ports before reusing an
old one. However, other platforms reuse ports much more aggressively.
net/http shouldn't know or care which kind of platform it is on —
dialing wild connections is risky and can interfere with other tests
no matter what platform we do it on.

Instead of making the second request after the server has completely
shut down, we can start (and finish!) the entire request while we are
certain that the listener has been closed but the port is still open
serving an existing request. If everything synchronizes as we expect,
that should guarantee that the second request fails.

Fixes #56421.

Change-Id: I56add243bb9f76ee04ead8f643118f9448fd1280
Reviewed-on: https://go-review.googlesource.com/c/go/+/476036
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
src/net/http/serve_test.go