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
net/http: nginx seems to require that entire request be read before writing response #15789
Comments
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. |
OK,I will try to provide a program. |
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, 项超 notifications@github.com wrote:
|
If I remove nginx, there is no error . |
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. |
So it sounds like the problem is that when using nginx, the entire request must be read before the response is written. I'll leave this for analysis during the 1.8 release. |
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. |
It seems golang should ensure that a FIN packet is sent before any RST packet. |
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
The text was updated successfully, but these errors were encountered: