libmpd-haskell icon indicating copy to clipboard operation
libmpd-haskell copied to clipboard

Only tries to connect to a single address

Open infinisil opened this issue 2 years ago • 1 comments

In https://github.com/vimus/libmpd-haskell/blob/1ec02deba33ce2a16012d8f0954e648eb4b5c485/src/Network/MPD/Core.hs#L123 only the first address out of many is tried. In case of the default host "localhost" however this returns 6 results for me:

ghci> import Network.Socket
ghci> traverse print =<< getAddrInfo (Just defaultHints) (Just "localhost") (Just "6600")
AddrInfo {addrFlags = [], addrFamily = AF_INET6, addrSocketType = Stream, addrProtocol = 6, addrAddress = [::1]:6600, addrCanonName = Nothing}
AddrInfo {addrFlags = [], addrFamily = AF_INET6, addrSocketType = Datagram, addrProtocol = 17, addrAddress = [::1]:6600, addrCanonName = Nothing}
AddrInfo {addrFlags = [], addrFamily = AF_INET6, addrSocketType = Raw, addrProtocol = 0, addrAddress = [::1]:6600, addrCanonName = Nothing}
AddrInfo {addrFlags = [], addrFamily = AF_INET, addrSocketType = Stream, addrProtocol = 6, addrAddress = 127.0.0.1:6600, addrCanonName = Nothing}
AddrInfo {addrFlags = [], addrFamily = AF_INET, addrSocketType = Datagram, addrProtocol = 17, addrAddress = 127.0.0.1:6600, addrCanonName = Nothing}
AddrInfo {addrFlags = [], addrFamily = AF_INET, addrSocketType = Raw, addrProtocol = 0, addrAddress = 127.0.0.1:6600, addrCanonName = Nothing}

In my case this causes it to fail to connect, supposedly because I don't have a local IPv6 interface:

$ mpc --host=::1
MPD error: Connection refused

I think this should be fixed by libmpd trying each of the returned addresses until one succeeds. This is also what libmpdclient does

It also looks like the defaultHints should be adjusted to only return ones with addrSocketType = Stream

infinisil avatar Sep 29 '21 01:09 infinisil