Skip to main content

Module net

Module net 

Source
Expand description

Networking utilities - Happy Eyeballs endpoint resolution.

When a URL contains localhost, the OS may resolve it to both [::1] (IPv6) and 127.0.0.1 (IPv4). If the server only listens on one protocol, the client stalls for ~2 s on every request while the first SYN times out. This module races a TCP connect to both addresses in parallel and rewrites the URL to use whichever responds first - eliminating that per-request penalty.

Functions§

resolve_localhost
If endpoint contains localhost, race IPv4 vs IPv6 TCP connects and return a rewritten URL using the winning literal address. If both fail (or the URL doesn’t use localhost), the original endpoint is returned unchanged.