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: nginx seems to require that entire request be read before writing response #15789
Sorry i can't provide runnable program, but I think this is a common problem, I find this error in many projects。
Nginx use upstream, total QPS is about 3000，and about 1 second, I see an error log in my nginx error log, the log like this:
if I use go1.3.3 to build this project , there is no error log.
I catch the TCP pocket
I doubt there is anything we can do if we don't have a way to recreate the problem. You will need to do some more debugging yourself to understand why and when the connection is being closed on the client side.
If this is a common problem, as you suggest, then I hope that somebody can provide a program that demonstrates it.
I can provide program now.
The client code
The server code
The nginx config
The nginx error log
when I build server code with go1.3.3 version, there is no "reset by peer" error in nginx error log,
In the server code, I use gzip reader to read body, I know this will return error, I just want to make this case.
Does the error occur if you remove nginx from the scenario ?
On Tue, May 24, 2016 at 6:06 PM, 项超 firstname.lastname@example.org wrote:
I update the service code like this
There is no errors when I use the follow code
It seems that I should read all of request data in body before write response.
referenced this issue
Sep 9, 2016
Yeah, this is a common situation with HTTP/1 implementations. I wouldn't even say "problem" because it's extremely ill-defined on whether you can read & write at the same time.
https://golang.org/pkg/net/http/#ResponseWriter does already say:
// Depending on the HTTP protocol version and the client, calling // Write or WriteHeader may prevent future reads on the // Request.Body. For HTTP/1.x requests, handlers should read any // needed request body data before writing the response. Once the // headers have been flushed (due to either an explicit Flusher.Flush // call or writing enough data to trigger a flush), the request body // may be unavailable. For HTTP/2 requests, the Go HTTP server permits // handlers to continue to read the request body while concurrently // writing the response. However, such behavior may not be supported // by all HTTP/2 clients. Handlers should read before writing if // possible to maximize compatibility. Write(byte) (int, error)
Unless there's some code in the standard library that writes before reading, I'm not sure there's anything for us to do here. Closing, but feel free to reopen if you disagree and I'm not understanding what this bug is about.