-
Notifications
You must be signed in to change notification settings - Fork 17.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: HTTP/2 response body Close method sometimes returns spurious context cancelation error (1.17.3 regression) #49366
Comments
Finalizing the stream (in A So if you read the full response, the request context is always canceled before I'm not immediately certain what the right fix is: |
Naive suggestion from someone without context: If |
That fixes the problem where we return |
@neild I'm not sure I'm following you. Altering whether the function returns Or are you saying that the problem I'm noticing is a symptom of a deeper problem, which is that |
Yes, that's right: |
This just hit us too; sorry for the +1 post. We reverted to the previous Go version because it's not feasible to change every instance where we check such errors (and not clear that's the right thing to do anyway). This feels like a pretty serious regression. |
Change https://golang.org/cl/362354 mentions this issue: |
Change https://golang.org/cl/361919 mentions this issue: |
We also saw this error in our logs when we upgraded to 1.17.3. We downgraded the log to warn level after seeing this issue to remove the noise. |
This issue is serious for me as I have a case when the entire body is lost before being processed. |
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>
@gopherbot Please open backport issues for 1.16 and 1.17 |
Backport issue(s) opened: #49558 (for 1.16), #49559 (for 1.17). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
becasue of this bug golang/go#49366 Signed-off-by: Krasi Georgiev <8903888+krasi-georgiev@users.noreply.github.com>
Change https://golang.org/cl/368084 mentions this issue: |
Change https://golang.org/cl/368085 mentions this issue: |
…sponse body read When sending a Request with a non-context deadline, we create a context with a timeout. This context is canceled when closing the response body, and also if a read from the response body returns an error (including io.EOF). Cancelling the context in Response.Body.Read interferes with the HTTP/2 client cleaning up after a request is completed, and is unnecessary: The user should always close the body, the impact from not canceling the context is minor (the context timer leaks until it fires). Fixes #49559. For #49366. Change-Id: Ieaed866116916261d9079f71d8fea7a7b303b8fb Reviewed-on: https://go-review.googlesource.com/c/go/+/361919 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> (cherry picked from commit 76fbd61) Reviewed-on: https://go-review.googlesource.com/c/go/+/368085 Reviewed-by: Michael Knyszek <mknyszek@google.com>
…sponse body read When sending a Request with a non-context deadline, we create a context with a timeout. This context is canceled when closing the response body, and also if a read from the response body returns an error (including io.EOF). Cancelling the context in Response.Body.Read interferes with the HTTP/2 client cleaning up after a request is completed, and is unnecessary: The user should always close the body, the impact from not canceling the context is minor (the context timer leaks until it fires). For #49366. Fixes #49558. Change-Id: Ieaed866116916261d9079f71d8fea7a7b303b8fb Reviewed-on: https://go-review.googlesource.com/c/go/+/361919 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> (cherry picked from commit 76fbd61) Reviewed-on: https://go-review.googlesource.com/c/go/+/368084 Reviewed-by: Michael Knyszek <mknyszek@google.com>
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>
What version of Go are you using (
go version
)?Go 1.17.3
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?linux/amd64
What did you do?
http.Client
with (any)Timeout
setDemo code:
(I'm pinging google.com as an easy way to get an HTTP/2 request going.)
What did you expect to see?
No error, at least not on the
resp.Body.Close()
call.What did you see instead?
For example:
Sometimes it takes a few iterations to hit an error.
This is HTTP/2-specific: with
GODEBUG=http2client=0
it does not reproduce.This does not occur in Go 1.17.2 but it started happening with 1.17.3.
I realize it's weird to be checking the
resp.Body.Close
error in the first place. This came up in the context of twirp; I'm going to send a PR to them to stop checking the error. Even so, I don't think we should get this error in the client. It's especially confusing because we get the error immediately (so it's not related to the 1 minute timeout specifically).I bisected on master to 7109323, which is CL 353870. The original x/net/http2 CL is CL 353390 and it was backported for Go 1.17.3 as CL 357683.
/cc @neild @bradfitz @nightlyone @fraenkel
The text was updated successfully, but these errors were encountered: