network-transport-tcp
network-transport-tcp copied to clipboard
Connection failure with localhost
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.
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.
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.
Note that the loopback interface does not always have address 127.0.0.1 on all systems.