Open andybons opened 3 years ago
Change https://golang.org/cl/290149 mentions this issue: net: report local address on unsuccessful TCP dial attempts
If we set Source, then it will be printed in the result from Error. And most of the time the Source on Dial is meaningless - it's the local computer and a random port address. I can see wanting it for debugging against tcpdump traces or the like. But we probably don't want to print it always - it's mostly noise, and these errors do get printed a lot, like every time a connection fails. And so if we add it to Source we'd have to add some extra bool to say "don't print it in the Error result".
Also, for the Dial call in question, we don't pick nor are we aware of the source address and port used by the kernel. We call getsockname after connect, but I'm not convinced getsockname is defined to work after connect fails (nor before it executes). (The man page agrees that a failed connect should not assume anything about the socket, presumably including not calling getsockname. It may or may not return something useful at all.)
So we may not be able to provide this information anyway. Note that the C code above does call getsockname without checking that connect has succeeded.
This proposal has been added to the active column of the proposals project and will now be reviewed at the weekly proposal review meetings. — rsc for the proposal review group
@andybons, can you say more about when this arises?
Placing on hold while I formulate a response :)
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yeppers
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When using
net.Dial
or its variants and a connection fails, it can be extremely helpful to know the source IP/port for diagnostic purposes, but it isn’t populated within theOpError
. The below code shows the behavior in action:What did you expect to see?
It would be nice if the
OpError
populated the source IP/port when it could, or allowed for clients to get access to it (say, if there were security concerns with exposing the source IP/port in theOpError
by default if it may be blindly bubbled up to clients).For reference, this is achieved through the C program below.
What did you see instead?
Only a destination IP/port in the error.
/cc @rwg-stripe @bobby-stripe @bradfitz @rsc