Commit fb394017 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: fix flaky TestTransportCancelBeforeResponseHeaders test

Add a couple more cases where we convert random network I/O errors
into errRequestCanceled if the request was forcefully aborted.

It failed ~1/1000 times without -race, or very easily with -race.
(due to -race randomizing some scheduling)

Fixes #11894

Change-Id: Ib1c123ce1eebdd88642da28a5948ca4f30581907
Reviewed-on: https://go-review.googlesource.com/18287Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent af768fdd
...@@ -1423,6 +1423,9 @@ WaitResponse: ...@@ -1423,6 +1423,9 @@ WaitResponse:
select { select {
case err := <-writeErrCh: case err := <-writeErrCh:
if err != nil { if err != nil {
if pc.isCanceled() {
err = errRequestCanceled
}
re = responseAndError{err: beforeRespHeaderError{err}} re = responseAndError{err: beforeRespHeaderError{err}}
pc.close(fmt.Errorf("write error: %v", err)) pc.close(fmt.Errorf("write error: %v", err))
break WaitResponse break WaitResponse
...@@ -1446,6 +1449,9 @@ WaitResponse: ...@@ -1446,6 +1449,9 @@ WaitResponse:
re = responseAndError{err: errTimeout} re = responseAndError{err: errTimeout}
break WaitResponse break WaitResponse
case re = <-resc: case re = <-resc:
if re.err != nil && pc.isCanceled() {
re.err = errRequestCanceled
}
break WaitResponse break WaitResponse
case <-cancelChan: case <-cancelChan:
pc.t.CancelRequest(req.Request) pc.t.CancelRequest(req.Request)
......
...@@ -1649,7 +1649,6 @@ func TestCancelRequestWithChannelBeforeDo(t *testing.T) { ...@@ -1649,7 +1649,6 @@ func TestCancelRequestWithChannelBeforeDo(t *testing.T) {
// Issue 11020. The returned error message should be errRequestCanceled // Issue 11020. The returned error message should be errRequestCanceled
func TestTransportCancelBeforeResponseHeaders(t *testing.T) { func TestTransportCancelBeforeResponseHeaders(t *testing.T) {
setFlaky(t, 11894)
defer afterTest(t) defer afterTest(t)
serverConnCh := make(chan net.Conn, 1) serverConnCh := make(chan net.Conn, 1)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment