-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: Transport.RoundTrip errors could be more informative #13667
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
True, but I think it's basically always been like this. And how often does this happen? I'm not against fixing this and making the errors more descriptive, but it's pretty low priority. I'd be happy to review code if others want to work on it. |
The reason this came up was that if you start a docker container with an exposed port but the process inside the container is not listening on the internal port, then the (admittedly braindead) docker daemon will SYNACK all incoming connections and then immediately FIN them. This seems like a generic-enough situation given the popularity of docker to care about this case. I'm up for putting in a cl to fix this. |
So interestingly, am able to get a meaningful error response as requested in the issue but not consistently. Please see gist https://gist.github.com/odeke-em/dc45c763d311210fbdd1 -- this is without modifying the logic in net/http except for just mere log.Println's |
Yes I have also seen the "transport closed before response was received" error on occasion. Could there be a race condition here? |
I don't think there is a data race. There is definitely a higher-level race of many things happening network-wise, though. Read net/http/transport.go's persistConn.roundTrip code. (which isn't a bug... failure events can just happen in different orders) |
CL https://golang.org/cl/18069 mentions this issue. |
I think this was already fixed by https://golang.org/cl/23160 But it could use a new test to confirm. |
Actually, this is somewhat intentional. See ea2376f which came out of #16465. But we should probably have different behavior on the first request on a connection at least. Much has changed in the past two releases, so it's probably time to revisit this. But too much changes this cycle too (Request.GetBody in Go 1.8) so I'll punt this to Go 1.9. (Incidentally, while thinking about this I realized Go 1.8 adding Request.GetBody meant we could've done more in terms of retries in the Transport. I just filed #17844 for Go 1.9) |
I made an HTTP request to a server that accepts all TCP connections and then immediately closes them. I was expecting a meaningful error such as "connection closed before request could be sent" but http.RoundTrip returned EOF.
Here are client and server snippets that reproduce this. The client:
Output is:
And the server:
Here is a dump of the TCP exchange:
The text was updated successfully, but these errors were encountered: