-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http, x/net/http2: support http2requestBody.Close() being called multiple times concurrently #51197
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
Comments
Example code to reproduce:
Then I can run it as:
And trigger the race with:
|
Change https://go.dev/cl/385874 mentions this issue: |
CC @neild. |
The race is a side effect of the fix for #46866, which causes ReverseProxy to always close the body of outgoing requests before returning. When the ReverseProxy handler returns early, this can result in racing closes: One by While the |
Change https://go.dev/cl/386495 mentions this issue: |
How do we get this change submitted to upstream? |
Now that the change has been approved, any idea on when it will be merged in? |
While no guarantees are made about the safety of repeated or concurrent closes of a request body, HTTP/1 request bodies are concurrency-safe and HTTP/2 ones should be as well. Fixes golang/go#51197 Change-Id: Id6527dc2932579cabc9cbe921c6e0b3b4a3d472c Reviewed-on: https://go-review.googlesource.com/c/net/+/386495 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
While no guarantees are made about the safety of repeated or concurrent closes of a request body, HTTP/1 request bodies are concurrency-safe and HTTP/2 ones should be as well. Fixes golang/go#51197 Change-Id: Id6527dc2932579cabc9cbe921c6e0b3b4a3d472c Reviewed-on: https://go-review.googlesource.com/c/net/+/386495 Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Used net/http2 with net/httputil/ReverseProxy.
Then ran a test with the
-race
flag.What did you expect to see?
No race conditions.
What did you see instead?
Race conditions.
Not quite sure how hard this will be to replicate cleanly to reproduce.
Basically, the http2 portion of net/http will close a request body when it’s done.
Also, the ProxyServer portion of net/http/httputil will close a request body when it’s done.
So the request body gets closed twice.
But the http2requestBody.Close() method, while obviously coded to support being called multiple times, will run into a race condition if Close() is called twice concurrently.
Very simple fix as well.
Current code:
Fixed code:
The text was updated successfully, but these errors were encountered: