Skip to content
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: Transport.RoundTrip errors could be more informative #13667

Open
alexflint opened this issue Dec 18, 2015 · 9 comments
Open

net/http: Transport.RoundTrip errors could be more informative #13667

alexflint opened this issue Dec 18, 2015 · 9 comments
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. help wanted NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Milestone

Comments

@alexflint
Copy link

go version go1.5 linux/amd64
Ubuntu 14.04.3 LTS

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:

package main

import (
    "fmt"
    "net"
    "net/http"
)

func main() {
    dialer := &net.Dialer{}
    transport := &http.Transport{
        Dial: dialer.Dial,
    }

    request, _ := http.NewRequest("GET", "http://127.0.0.1:19870/", nil)
    _, err := transport.RoundTrip(request)
    fmt.Println(err)
}

Output is:

EOF

And the server:

package main

import "net"

func main() {
    ln, _ := net.Listen("tcp", ":19870")
    conn, _ := ln.Accept()
    conn.Close()
}

Here is a dump of the TCP exchange:

17:16:31.017342 IP localhost.52287 > localhost.19870: Flags [S], seq 3991906392, win 43690, options [mss 65495,sackOK,TS val 27880590 ecr 0,nop,wscale 7], length 0
E..<..@.@.w..........?M....X.........0.........
..l.........
17:16:31.017356 IP localhost.19870 > localhost.52287: Flags [S.], seq 530413255, ack 3991906393, win 43690, options [mss 65495,sackOK,TS val 27880590 ecr 27880590,nop,wscale 7], length 0
E..<..@.@.<.........M..?..v....Y.....0.........
..l...l.....
17:16:31.017367 IP localhost.52287 > localhost.19870: Flags [.], ack 1, win 342, options [nop,nop,TS val 27880590 ecr 27880590], length 0
E..4..@.@.w..........?M....Y..v....V.(.....
..l...l.
17:16:31.017514 IP localhost.19870 > localhost.52287: Flags [F.], seq 1, ack 1, win 342, options [nop,nop,TS val 27880591 ecr 27880590], length 0
E..4.F@.@."|........M..?..v....Y...V.(.....
..l...l.
17:16:31.019472 IP localhost.52287 > localhost.19870: Flags [F.], seq 1, ack 2, win 342, options [nop,nop,TS val 27880591 ecr 27880591], length 0
E..4..@.@.w..........?M....Y..v....V.(.....
..l...l.
17:16:31.019493 IP localhost.19870 > localhost.52287: Flags [.], ack 2, win 342, options [nop,nop,TS val 27880591 ecr 27880591], length 0
E..4.G@.@."{........M..?..v....Z...V.(.....
..l...l.
@bradfitz bradfitz changed the title http.Transport.RoundTrip returns EOF for empty response net/http: Transport.RoundTrip errors could be more informative Dec 18, 2015
@bradfitz
Copy link
Contributor

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.

@bradfitz bradfitz added this to the Unplanned milestone Dec 18, 2015
@alexflint
Copy link
Author

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.

@odeke-em
Copy link
Member

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
and snippets
screen shot 2015-12-17 at 6 59 34 pm

@alexflint
Copy link
Author

Yes I have also seen the "transport closed before response was received" error on occasion. Could there be a race condition here?

@bradfitz
Copy link
Contributor

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)

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/18069 mentions this issue.

@bradfitz bradfitz modified the milestones: Go1.7, Unplanned Feb 1, 2016
@rsc rsc modified the milestones: Go1.8, Go1.7 May 18, 2016
@bradfitz
Copy link
Contributor

I think this was already fixed by https://golang.org/cl/23160

But it could use a new test to confirm.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 7, 2016
@alexflint alexflint added the Testing An issue that has been verified to require only test changes, not just a test failure. label Nov 7, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Nov 8, 2016

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)

@bradfitz bradfitz removed this from the Go1.12 milestone May 18, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Jun 1, 2018
@andybons andybons modified the milestones: Go1.12, Go1.13 Feb 12, 2019
@andybons andybons removed this from the Go1.13 milestone Jul 8, 2019
@hktalent
Copy link

me too

net/http.(*persistConn).roundTrip(0xc00b0c0b40, 0xc009e14a00)
	/usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:2620 +0x974
net/http.(*Transport).roundTrip(0xc00b620dc0, 0xc01739f600)
	/usr/local/Cellar/go/1.18.3/libexec/src/net/http/transport.go:594 +0x7c9
net/http.(*Transport).RoundTrip(0xc01739f600?, 0x6e94d40?)
	/usr/local/Cellar/go/1.18.3/libexec/src/net/http/roundtrip.go:17 +0x19
net/http.send(0xc01739f500, {0x6e94d40, 0xc00b620dc0}, {0x59a3880?, 0x408e301?, 0x826f2c0?})
	/usr/local/Cellar/go/1.18.3/libexec/src/net/http/client.go:252 +0x5d8
net/http.(*Client).send(0xc00bbec0c0, 0xc01739f500, {0x203002?, 0xc00bbec120?, 0x826f2c0?})
	/usr/local/Cellar/go/1.18.3/libexec/src/net/http/client.go:176 +0x9b
net/http.(*Client).do(0xc00bbec0c0, 0xc01739f500)
	/usr/local/Cellar/go/1.18.3/libexec/src/net/http/client.go:725 +0x8f5
net/http.(*Client).Do(...)
	/usr/local/Cellar/go/1.18.3/libexec/src/net/http/client.go:593

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
early-in-cycle A change that should be done early in the 3 month dev cycle. help wanted NeedsFix The path to resolution is known, but the work has not been done. Testing An issue that has been verified to require only test changes, not just a test failure.
Projects
None yet
Development

No branches or pull requests

10 participants