Hi,

I'd like to contribute to JDK-8371576 [1], where HttpURLConnection fails 
immediately
if the first DNS-resolved IP address is unreachable, even when other valid 
addresses exist.

I analyzed the issue and identified the root cause in NetworkClient.doConnect():
- It uses new InetSocketAddress(server, port), which only attempts the first 
resolved address
- This affects HttpURLConnection, FTP, and other users of NetworkClient
- The modern HttpClient has a similar issue in 
PlainHttpConnection.connectAsync()

Proposed fix:
- Explicitly resolve all addresses via InetAddress.getAllByName()
- Attempt connections sequentially until one succeeds
- Distribute the timeout across attempts to preserve existing behavior
- Introduce a system property: jdk.net.enableDNSFallback (default: true)

This would address the legacy APIs. Since the modern HttpClient appears to have 
the same issue,
would you prefer to fix both in a single change or handle them separately?

I'm happy to work on this if the issue is available.

Thanks,  
Hyunsu Eun

[1] https://bugs.openjdk.org/browse/JDK-8371576

Reply via email to