Skip to content

Commit

Permalink
net/http: fix a race in TestResponseControllerSetPastReadDeadline
Browse files Browse the repository at this point in the history
If the Write goroutine is delayed for long enough after its first
Write, the handler may have closed both the readc and donec channels
by the time it selects over them, and the donec case may be randomly
chosen. Handle that case by explicitly checking readc as well.

This fixes a race accidentally introduced in CL 482935 and observed in
https://build.golang.org/log/fa684750994d1fda409722f144b90c65b4c52cf9.

For golang#59447.

Change-Id: I5c87a599910cf8c1d037e5bbce68bf35afd55d61
Reviewed-on: https://go-review.googlesource.com/c/go/+/483036
TryBot-Result: Gopher Robot <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Apr 7, 2023
1 parent 39986d2 commit 38dadcc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/net/http/responsecontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,12 @@ func testResponseControllerSetPastReadDeadline(t *testing.T, mode testMode) {
select {
case <-readc:
case <-donec:
t.Errorf("server handler unexpectedly exited without closing readc")
return
select {
case <-readc:
default:
t.Errorf("server handler unexpectedly exited without closing readc")
return
}
}
pw.Write([]byte("two"))
}()
Expand Down

0 comments on commit 38dadcc

Please sign in to comment.