network-transport-tcp icon indicating copy to clipboard operation
network-transport-tcp copied to clipboard

Connection failure with localhost

Open aherrmann opened this issue 6 years ago • 3 comments

I'm observing failures when trying to connect and send messages to localhost:

TransportError ConnectFailed "Network.Socket.recvBuf: resource vanished (Connection reset by peer)"

I did not construct a minimal example, but I've traced the issue to the following commit to network-transport-tcp. In particular the original failure occurs in this line. The issue is that at this point sockAddr has the value ::1 but decodeSockAddr only supports IPv4 addresses. Adding a dummy case that handles IPv6 and always returns 127.0.0.1:<port> fixes the connection failures in my case. The IPv6 address originates from this call to N.getAddrInfo when host="localhost". A work-around is to always use 127.0.0.1 instead of localhost. This depends on system configuration, as the issue was only observed on some machines.

aherrmann avatar Mar 08 '18 12:03 aherrmann

I believe n-t-tcp is only meant to support IPv4 addresses this far. That doesn't mean that it couldn't be enhanced if your project needs it.

facundominguez avatar Mar 08 '18 12:03 facundominguez

The project doesn't need IPv6, so passing 127.0.0.1 instead of localhost is a viable work-around.

Forgot to mention: I tried passing hints with addrFamily = AF_INET in the above mentioned location to force getAddrInfo to return an IPv4 address, but it caused the program to hang.

aherrmann avatar Mar 08 '18 13:03 aherrmann

Note that the loopback interface does not always have address 127.0.0.1 on all systems.

mboes avatar Mar 08 '18 14:03 mboes