Sharawey74 opened a new pull request, #3332: URL: https://github.com/apache/httpcomponents-client/pull/3332
Fixes #3313 (HTTPCLIENT-2436). The async client gave up as soon as the TLS handshake failed on the first resolved address, while the classic client moved on to the next one. With `localhost` resolving to `127.0.0.1` and `::1` and a server that never answers the handshake, classic gave up after 2 x handshake timeout and async after 1 x, so the same `TlsConfig` behaved differently depending on the transport. This makes both transports follow one rule, as agreed in the issue: - the handshake fails with a `CertificateException` or an `SSLPeerUnverifiedException` anywhere in its cause chain: fail right away, since every address presents the same certificate - any other `IOException` (handshake timeout, connection reset, peer closing mid-handshake, TLS alert): try the next address Three commits: 1. **Fall back to remaining addresses when TLS fails after a connect** is @arturobernalg's commit from https://github.com/arturobernalg/httpcomponents-client/commit/729b6876f, applied unchanged with him as author. It adds a `SessionValidator` hook to `MultihomeIOSessionRequester` that runs the TLS handshake on every connected session before it is accepted, for both the sequential path and the Happy Eyeballs race, so `MultihomeConnectionInitiator` does not change. The commit message has the details, including the cancellation hardening. 2. **Stop trying other addresses when the peer's certificate is rejected** adds `ConnectExceptionSupport.isPeerCertificateFailure`, which walks the whole cause chain (cycle-safe), and uses it in four places: the async sequential path and race fallback, and the classic sequential path and race fallback. Classic used to retry on certificate failures too, so it now stops there the same way. 3. **Test that certificate failures do not try other addresses against a real server** adds `TestTlsCertificateFailureNoFallback` in `httpclient5-testing` (see below). A peer closing the connection mid-handshake and a TLS alert both surface as a bare `SSLHandshakeException`, so the check goes by cause type rather than by `SSLException`. A host name mismatch is covered under both the built-in and the client-side verification: `CertificateException` in the first case, `SSLPeerUnverifiedException` in the second. H2-only clients are not covered and can be a follow-up. Tests: - `ConnectExceptionSupportTest`: direct and nested causes, non-certificate handshake failures, `null`, and a cyclic cause chain - `DefaultHttpClientConnectionOperatorTest`: a certificate failure and a peer-unverified failure on the first of two real loopback addresses stop after one handshake, a non-certificate `SSLHandshakeException` still falls back; each with and without Happy Eyeballs - `DefaultAsyncClientConnectionOperatorTest`: the same two failure kinds stop the async operator without a second connect attempt, with and without Happy Eyeballs - `TestTlsCertificateFailureNoFallback`: classic and async, with and without Happy Eyeballs, against a real TLS server whose certificate is untrusted or issued to another host name, with the host name checked under both `BUILTIN` and `CLIENT`. The request must fail with a certificate failure and the second address must never be connected to. All 12 cases of the real-server test and the 8 new operator tests fail without the second commit. `mvn -pl httpclient5 install` passes (1270 tests, japicmp included), as do `TestTlsCertificateFailureNoFallback`, `TestHappyEyeballsTlsFallback`, `TestHappyEyeballsTlsFallbackAsync` and `TestHttpAsyncMinimalTlsHandshake`, on both JDK 21 and JDK 25. `TestHappyEyeballsTlsFallbackAsync.cancelDuringFallbackAfterRealTlsFailure_abortsPendingAttempt` failed once in five runs here, which matches the flakiness noted in the first commit's message (the httpcore5 cancellation window). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
