-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
x/net/http2: indefinite hangs when closing response body #48908
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Comments
toothrot
added
the
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
label
Oct 12, 2021
Change https://golang.org/cl/355491 mentions this issue: |
gopherbot
pushed a commit
to golang/net
that referenced
this issue
Oct 13, 2021
After RoundTrip returns, closing the Response's Body should interrupt any ongoing write of the request body. Close the Request's Body to unblock the body writer. Take additional care around the use of a Request after its Response's Body has been closed. The RoundTripper contract permits the caller to modify the request after the Response's body has been closed. Updates golang/go#48908. Change-Id: I261e08eb5d70016b49942d72833f46b2ae83962a Reviewed-on: https://go-review.googlesource.com/c/net/+/355491 Trust: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Change https://golang.org/cl/357095 mentions this issue: |
dteh
pushed a commit
to dteh/fhttp
that referenced
this issue
Jun 22, 2022
After RoundTrip returns, closing the Response's Body should interrupt any ongoing write of the request body. Close the Request's Body to unblock the body writer. Take additional care around the use of a Request after its Response's Body has been closed. The RoundTripper contract permits the caller to modify the request after the Response's body has been closed. Updates golang/go#48908. Change-Id: I261e08eb5d70016b49942d72833f46b2ae83962a Reviewed-on: https://go-review.googlesource.com/c/net/+/355491 Trust: Damien Neil <dneil@google.com> Run-TryBot: Damien Neil <dneil@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Closing a response body can block indefinitely under at least two circumstances:
Closing a body with unread data returns flow-control tokens for the unread data. If the underlying
net.Conn
for the request is write-blocked, the attempt to return the tokens can block either while acquiring the stream write mutex, or while writing the window update to the connection.Closing a response body waits for the request stream to be cleaned up, or the request context to expire, whichever comes first. This ensures that there is no lingering per-request state remaining after a
nil
response fromresp.Body.Close
. (We don't guarantee this property in the package docs, but we do have tests asserting this property. For example, we assume that a request no longer counts against the concurrency limit after a nil response fromClose
.) If the request writer is blocked reading the request body, we currently have no way to interrupt it andresp.Body.Close
will block until the request context is canceled (if ever).My first thought was that closing the response body could close the request body, interrupting the request writer, but this will require caution: The
RoundTripper
contract permitsRoundTrip
to access fields of the request up to the point where the request body is closed. If we change the place we close the request body, we need to be very cautious that we don't access any part of the request after that point.Test for this second case:
The text was updated successfully, but these errors were encountered: