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

Cannot connect to Server using IPv6 #271

Open
Kilobyte22 opened this issue May 10, 2024 · 3 comments
Open

Cannot connect to Server using IPv6 #271

Kilobyte22 opened this issue May 10, 2024 · 3 comments

Comments

@Kilobyte22
Copy link

Expected behaviour

  • When connecting to a hostname with AAAA record, but no A record, from i host with IPv6-connectivity I would expect a connection via IPv6 to succeed, without needing additional configuration
  • When connecting to a hostname with both AAAA record and A record from a host without any IPv4 connectivity i would expect a connection via IPv6 to be established, without needing additional configuration

Observed behaviour

  • In first case: {:error, %Mint.TransportError{reason: :nxdomain}}
  • In second case: {:error, %Mint.TransportError{reason: :enetunreach}}

Possible solutions

Try IPv6 first, if the hostname does have an AAAA record. If that fails with some kind of network error, try IPv4. The result of this check should probably be cached for performance reasons. A more complex, but also more robust solution would be to implement happy eyeballs, as specified in RFC 8305.

This issue seems very similar to benoitc/hackney#206, though hackney at least works properly in the first case. The hackney issue also goes into more detail on possible solutions.

@ruslandoga
Copy link
Contributor

ruslandoga commented Jun 6, 2024

👋 @Kilobyte22

Have you tried passing inet6: true to :transport_opts? It would make Mint attempt IPv6 connection with IPv4 fallback.

{Finch,
 name: MyFinch,
 pools: %{
   default: [conn_opts: [transport_opts: [inet6: true]]]
 }}

@Kilobyte22
Copy link
Author

Thanks for the info, I did in fact not see this option and it does what i want!

I still believe however that this should be default behaviour, as many developers will not enable this option, leading to their applications not being compatible with IPv6-Only Environments. This then makes it a lot more annoying for anyone trying to deploy it. I also see no disadvantage to enabling this by default, as this has been the default in basically any other ecosystem for well over a decade, possibly event more than 20 years.

I can also provide a quick PR if you want me to.

@feld
Copy link

feld commented Jun 12, 2024

This is a known issue with Erlang/Elixir. If you want a universal solution that attempts IPv6 first if there's an AAAA record you can include this dependency which will hijack :gen_tcp.connect and things should just work as you expect for all software, not just Mint. I'm hopeful that we'll see a proper Happy Eyeballs implementation in OTP in the future.

https://github.com/skunkwerks/inet64_tcp/

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

3 participants