Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
net/http: expose dialing errors from net package #23827
I would like to get meaningful errors from the net package. Right now I can not decide if I got an error while a connection is already established or if it's while creating a TCP or TLS handshake.
The code shows a workaround wrapping a net.Dialer to decide if the error happened was during Dial or an already established connection.
What version of Go are you using (
Running this example locally produce:
so the "connection refused" returned by Dial definitely implements net.Error interface.
If you got the error from net.Dial, it was due to establishing the connection.
If you got the error from Read or Write, it was from an already established connection.
It seems that your bug report is actually about net/http, not about the net package, as stated in your bug title.
Marking this as a duplicate of #14203.
FYI: I changed my example code to show the problem more clearly.
@artyom, @bradfitz maybe it's more a documentation issue for the meaning of Temporary(). My tests can not show, that Temporary fails, but it seems a bit weird to me. I also looked into the Go src code in $GOROOT and I see there some cases, which I would do a retry, for example tlsHandshakeTimeoutError is retrieable from the point of layer7 protocols view, but returns true in Temporary():
In general it's not only about "connection refused", here some other examples with a backend socat-test and logs from running the go code:
slow backend (see the $(sleep 1) that is the value for header X-Foo):
client logs for slow backend:
client logs without having a backend
middlebox that silently drop packets (iptables -I INPUT -p tcp --dst 127.0.0.1 --dport 10000 -j DROP)
test tls handshake failures