Repository navigation
Do not resolve the peer host name on every TLS handshake - #132627
thevar1able merged 1 commit into
Conversation
Since `openSSL.client.extendedVerification` is on by default (ClickHouse#116724, relanded by ClickHouse#126138), `SecureSocketImpl::verifyPeerCertificateImpl` evaluated the loopback exemption `isLocalHost(hostName)` before `X509_check_host`. `isLocalHost` builds `SocketAddress(hostName, 0)`, which for a host name calls an uncached `getaddrinfo`, so every outbound TLS handshake did one DNS lookup that the TCP connect (served by the cached `DNSResolver`) never needed. A cold query over a `web` or `s3` disk opens many new HTTPS connections, so the lookups add up. The exemption only matters when the certificate does not name the host; check it only then. The result is the same for every certificate: the same default, the same loopback exemption, and `strict` mode still never exempts. Reported in ClickHouse#116724 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings), plus my own review of the diff (no code findings; two wording fixes in the PR description).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261118-110104 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-40:20261118-101200 |
|
Workflow [PR], commit [f85c977] Summary: ✅
AI ReviewSummaryPR #132627, reviewed at Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
81cc0d9
Related: #116724
Related: #126138
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Outbound TLS connections no longer resolve the server host name during the handshake when the server certificate names that host. Since hostname verification of server certificates became the default, every new HTTPS connection (for example to a
webors3disk) did this extra lookup, which slowed down cold queries.Description
@ nihalzp reported that since #116724 (relanded by #126138) six cold queries of ClickBench
ClickHouse (web)take 5.2-5.6 s instead of 0.6-1.4 s (results).Root cause: with
openSSL.client.extendedVerificationon by default,SecureSocketImpl::verifyPeerCertificateImplevaluated the loopback exemptionisLocalHost(hostName)beforeX509_check_host.isLocalHostbuildsSocketAddress(hostName, 0), which calls an uncachedgetaddrinfofor a host name. The connection itself uses the cachedDNSResolver, so every new TLS connection did one extra lookup.Change: check the exemption only when the certificate does not name the host. The result is the same for every certificate, and
strictstill never exempts. A lookup remains only on the loopback exemption path, or before a connection is rejected.Validation (master vs this PR): a
url()read of N files from a local HTTPS endpoint whose certificate nameslocalhostdid 17 and 65 lookups for 16 and 64 handshakes on master, and 1 for both with this PR. Accept/reject results and error texts are identical for IP-literal and name loopback mismatches,strict, a non-loopback mismatch andextendedVerification = false. ClickBenchhitsattached from the samewebendpoint, cold Q37 (65 handshakes): 66 DNS queries on master, 1 with this PR. This box uses a local caching resolver, so I did not reproduce the 5 s and see no wall-clock difference here.No new test: the verification result does not change and the lookup is not observable from SQL.
00505_shard_secure,00505_secureand03595_parallel_replicas_join_remotecover the exemption path and pass.The lookup is also in 26.3, 26.7, 26.8 and 26.9 (backports of #116724).
🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/132627]
Version info
26.11.1.2792-master(included in26.11and later)