Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http: document that it's illegal to reuse a Request concurrently from multiple goroutines #21780
There is a small race in reusing
The code centers around transport.go's
For two requests a and b that execute back to back:
Also note that this is only the http1 stack and is harder to notice against URLs that have redirects.
What version of Go are you using (
This bug's title ("when reusing requests") made me think this was about back-to-back serial re-use of Requests, but the description and repro above (https://play.golang.org/p/BP7YCP2D4J) show that this is really about about concurrent use of the same request.
I suppose this could be made to work at least for GETs, but I'm not sure it's worth it. If it doesn't work for POSTs or things with bodies, I think I'd rather just document one consistent rule: that you can't use a Request concurrently by multiple goroutines.
changed the title
net/http: incorrect `errRequestCanceled` returns when reusing requests
Jul 9, 2018
Changing the benchmark to be serial reproduces this for me as well:
As far as I can tell, this is more in line with reusing a request serially back-to-back.