Skip to content

Commit f0573a1

Browse files
committed
http2: avoid spurious context cancelation error from Response.Body.Close
When a request has a deadline set, the net/http package can cancel the request context after reading an error (including io.EOF) from the response body. Avoid returning a spurious error from transportResponseBody if the request context is canceled. For golang/go#49366. Change-Id: I645466a1d6e405bdf17b3cc087204e4622a140eb Reviewed-on: https://go-review.googlesource.com/c/net/+/362354 Trust: Damien Neil <[email protected]> Run-TryBot: Damien Neil <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 58aab5e commit f0573a1

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

http2/transport.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,10 @@ func (b transportResponseBody) Close() error {
24522452
select {
24532453
case <-cs.donec:
24542454
case <-cs.ctx.Done():
2455-
return cs.ctx.Err()
2455+
// See golang/go#49366: The net/http package can cancel the
2456+
// request context after the response body is fully read.
2457+
// Don't treat this as an error.
2458+
return nil
24562459
case <-cs.reqCancel:
24572460
return errRequestCanceled
24582461
}

0 commit comments

Comments
 (0)