diff options
| author | Damien Neil <dneil@google.com> | 2025-03-17 15:43:47 -0700 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-03-18 10:52:10 -0700 |
| commit | a17c092c2c5e8ad45482ebbb9e17ef7f92edb96c (patch) | |
| tree | 19f19a2c60a57342401c3e7a39f5f333561f9ccc /src/net/http/transport_test.go | |
| parent | 5916bc5b5796e8fd15f3b4e95c945f5f4933e1d5 (diff) | |
| download | go-a17c092c2c5e8ad45482ebbb9e17ef7f92edb96c.tar.xz | |
net/http: add onClose hook to fake net listener
Avoids a race condition: If we set an onClose hook on a conn
created by a listener, then setting the hook can race with
the connection closing.
Change-Id: Ibadead3abbe4335d41f1e2cf84f4696fe98166b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/658655
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/net/http/transport_test.go')
| -rw-r--r-- | src/net/http/transport_test.go | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 7166c11279..431dc4ee20 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -4250,6 +4250,10 @@ func testTransportIdleConnRacesRequest(t testing.TB, mode testMode) { cst.li.onDial = func() { <-dialc } + closec := make(chan struct{}) + cst.li.onClose = func(*fakeNetConn) { + <-closec + } ctx, cancel := context.WithCancel(context.Background()) req1c := make(chan error) go func() { @@ -4279,10 +4283,6 @@ func testTransportIdleConnRacesRequest(t testing.TB, mode testMode) { // // First: Wait for IdleConnTimeout. The net.Conn.Close blocks. synctest.Wait() - closec := make(chan struct{}) - cst.li.conns[0].peer.onClose = func() { - <-closec - } time.Sleep(timeout) synctest.Wait() // Make a request, which will use a new connection (since the existing one is closing). |
