sneako / finch

Elixir HTTP client, focused on performance
MIT License
1.23k stars 114 forks source link

Cannot connect to Server using IPv6 #271

Open Kilobyte22 opened 1 month ago

Kilobyte22 commented 1 month ago

Expected behaviour

Observed behaviour

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 https://github.com/benoitc/hackney/issues/206, though hackney at least works properly in the first case. The hackney issue also goes into more detail on possible solutions.

ruslandoga commented 4 weeks ago

👋 @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 commented 3 weeks ago

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 commented 3 weeks ago

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/