denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.05k stars 5.23k forks source link

Implement Happy Eyeballs for TCP connections #25661

Open lucacasonato opened 5 days ago

lucacasonato commented 5 days ago

Right now we generally prefer IPv6 to IPv4 addresses when connecting to services. This unfortunately causes users to run into "connection failed" errors when their service does not actually listen on IPv6 (even though the DNS resolves to an IPv6 address).

Happy Eyeballs fixes this. It establishes connections to multiple addresses in parallel and uses the first one that connects.

seanmonstar commented 4 days ago

As on potential option, the HttpConnector in hyper-util provides happy eyeballs, and it returns a TcpStream (just pluck it out of the TokioIo wrapper). It could be as easy as replacing the call of TcpStream::connect with a http_connector.call().