-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: data race in concurrent req.Body.{Close,Read} with 100-continue expected #30580
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
See the documentation for Handler, https://golang.org/pkg/net/http/#Handler.
You are violating the concurrently rule. |
Thanks @fraenkel, I investigated a bit further and found that the data race and nil pointer dereference are not the same underlying issue. The data race can be triggered by any handler that concurrently calls |
I agree with @fraenkel that this isn't a bug because this code is violating the rules: srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
go r.Body.Read(make([]byte, 1024))
go r.Body.Close()
})) |
@bradfitz please have another look at this sample code, it triggers the race detector I think without violating the rules: srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
var wg sync.WaitGroup
wg.Add(2)
go func() { r.Body.Read(make([]byte, 1024)); wg.Done() }()
go func() { r.Body.Close(); wg.Done() }()
wg.Wait()
})) |
Thanks. I'm not sure concurrent Read & Close is legal in this context, but maybe it should be. I'll use this bug to investigate and either fix or document. |
Its a bit more than just Read & Close. Just for kicks I modified the example to do concurrent reads of 1 byte.
|
The problem with Adding a simple lock would solve he problem:
I'm not sure it's the right way. cc @bradfitz |
We're running https://github.com/fabiolb/fabio as a load balancing solution and we are seeing this panic happening whenever we have concurrent requests to the same Host and path and sending the |
Is this related to #26253 ? |
@bradfitz what do you think about @cuonglm's suggestion in #30580 (comment)? @cuonglm would you like to send a CL to get the train rolling? Thank you! |
Please answer these questions before submitting your issue. Thanks!
What did you do?
https://gist.github.com/benburkert/76548cfac5aa6761fab2f88783b673aa
What did you expect to see?
No output.
What did you see instead?
System details
The text was updated successfully, but these errors were encountered: