haskell-distributed / network-transport-tcp

TCP Realisation of Network.Transport
http://haskell-distributed.github.com
BSD 3-Clause "New" or "Revised" License
30 stars 27 forks source link

Connection failure with localhost #71

Open aherrmann opened 6 years ago

aherrmann commented 6 years ago

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.

facundominguez commented 6 years ago

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.

aherrmann commented 6 years ago

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.

mboes commented 6 years ago

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