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: EOF returned from http.Transport #53472
Comments
that's not a raw EOF, it's a |
Oops, you’re completely correct. I was too focused on the user-visible text rather than on the type. |
At least using the func main() {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
panic(err)
}
go server(ln)
req, err := http.NewRequest(http.MethodGet, fmt.Sprintf("http://%s/", ln.Addr().String()), nil)
if err != nil {
panic(err)
}
res, err := http.DefaultTransport.RoundTrip(req)
fmt.Printf("res=%#v, err=%v (%#v) isEOF=%v\n", res, err, err, err == io.EOF)
} prints
|
To be specific, my primary concern is about the lack of a clear user-visible error message text. Right now error messages in logs just say “EOF” with little to allow diagnosing the failure further: it doesn’t indicate the relevant component (client / server / proxy / hypothetically something else like a corrupt local (certificate?) file). I can, of course, wrap the So I’d prefer receiving a more descriptive error message from the net/http client. |
cc @neild |
I just like to mention that I also struggle here. tr := http.DefaultTransport.(*http.Transport).Clone()
tr.ExpectContinueTimeout = 10 * time.Second
tr.DisableKeepAlives = true
tr.IdleConnTimeout = 10 * time.Second
client := http.Client{
Timeout: 10 * time.Second,
Transport: tr
} In a loop I create a new request and pass it to the client: req, err := http.NewRequest("GET", u, nil)
...
resp, err := c.client.Do(req) Most of the time err is nil - which is expected behaviour because the URL is valid and a valid response should be delivered. I test this in parallel with my browser. But in a few cases I get back an EOF error. Without any further information. In there a It's very likely somehow related to the host. In parallel I do exactly the same with another (local go-) server and I never get that EOF error. Still, I have no idea what's wrong here. I guess I have to dig even more into it. I just like to mention here that it would be really, really nice to get better error messages here, especially because the error chain doesn't pass a stack trace. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Given a HTTP server that reads the request, but (cleanly) closes the connection without producing any response:
What did you expect to see?
An error saying something about an unexpectedly closed connection.
What did you see instead?
i.e. the error is
io.EOF
, which seems inconsistent with the official definition of that value:Notes
I appreciate that this might not be possible to change due to the compatibility promise.
The immediate cause is
go/src/net/http/transport.go
Line 2092 in 3fcbfb0
io.EOF
, it is wrapped ingo/src/net/http/transport.go
Line 2109 in 3fcbfb0
io.EOF
again, with no logic anywhere to turn it into an “this was unexpected” error.The text was updated successfully, but these errors were encountered: