Iterate through all DNS entries in connect CLI#2906
Merged
Conversation
The `openssl sclient -connect` CLI command would only attempt to connect to the first resolved DNS entry. Failing that, it considers the entire connection attempt failed. This change updates the command to iterate through the linked list of entries until it can successfully connect. This is in-line with upstream [OpenSSL](https://github.com/openssl/openssl/blob/OpenSSL_1_1_1-stable/apps/s_socket.c#L93). It's particularly useful in cases where the first address resolved is either unavailable or otherwise unusable. This can be common when trying to resolve an address such as `localhost` and the OS returns the ipv6 loopback address before the ipv4 version and your web server is only listening with ipv4.
justsmth
approved these changes
Dec 15, 2025
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2906 +/- ##
==========================================
- Coverage 78.15% 78.14% -0.01%
==========================================
Files 687 687
Lines 118579 118577 -2
Branches 16671 16674 +3
==========================================
- Hits 92671 92665 -6
- Misses 25019 25023 +4
Partials 889 889 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
WillChilds-Klein
approved these changes
Dec 15, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issues:
N/A
Description of changes:
The
openssl sclient -connectCLI command would only attempt to connect to the first resolved DNS entry. Failing that,it considers the entire connection attempt failed. This change updates the command to iterate through the linked list of
entries until it can successfully connect. This is in-line with upstream OpenSSL.
It's particularly useful in cases where the first address resolved is either unavailable or otherwise unusable. This can
be common when trying to resolve an address such as
localhostand the OS returns the ipv6 loopback address before theipv4 version and your web server is only listening with ipv4.
Call-outs:
I did not exhaustively consider other uses of this function beyond this specific CLI tool. A glance check of the references suggests low usage and it's still the right change to make overall.
Testing:
Tested this in a build container which resolves
localhostas[::1, 127.0.0.1]with a web server that listens on ipv4 and asserted that the CLI tool can connect successfully to that web server.CI
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.