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 <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/http2/transport.go b/http2/transport.go
index bb07d8a..9c41179 100644
--- a/http2/transport.go
+++ b/http2/transport.go
@@ -2452,7 +2452,10 @@
select {
case <-cs.donec:
case <-cs.ctx.Done():
- return cs.ctx.Err()
+ // See golang/go#49366: The net/http package can cancel the
+ // request context after the response body is fully read.
+ // Don't treat this as an error.
+ return nil
case <-cs.reqCancel:
return errRequestCanceled
}