Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only tries to connect to a single address #136

Open
infinisil opened this issue Sep 29, 2021 · 1 comment
Open

Only tries to connect to a single address #136

infinisil opened this issue Sep 29, 2021 · 1 comment

Comments

@infinisil
Copy link

In

addr:_ <- liftIO $ getAddr host port
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

@psibi
Copy link
Collaborator

psibi commented Sep 29, 2021

Sounds fine. I would be happy to accept a PR for the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants