Skip to content

HTTPCLIENT-2436: Fall back to remaining addresses after a TLS failure (RFC 8305) - #3336

Open
arturobernalg wants to merge 1 commit into
apache:masterfrom
arturobernalg:fix-tls-fallback-happy-eyeballs
Open

arturobernalg wants to merge 1 commit into
apache:masterfrom
arturobernalg:fix-tls-fallback-happy-eyeballs

Conversation

@arturobernalg

Copy link
Copy Markdown
Member

SessionValidator falls back to the next address on a TLS failure (sequential or Happy-Eyeballs), closing the same gap #936 fixed for classic. Cancel-during-fallback test disabled: real core race in SingleCoreIOReactor losing cancel(), HTTPCORE ticket to follow.

@arturobernalg

Copy link
Copy Markdown
Member Author

@Sharawey74 please check

@ok2c

ok2c commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

@arturobernalg All these verbose comments are AI generated, are they not?

I have absolutely no problem with change-sets generated by AI or with AI assistance of AI but I am not sure comments like that bring much. They will likely start rotting as soon as the same code gets touched by someone who does not use AI.

@Sharawey74

Copy link
Copy Markdown

@Sharawey74 please check

Thanks @arturobernalg. My two commits from #3332 apply cleanly on top of this one, so I'll open them as two separate PRs as @ok2c asked: the certificate fail-fast change, then the real-server test on top of it.

… (RFC 8305)

MultihomeIOSessionRequester only retried a TCP-level connect failure
across the resolved addresses; a TLS failure on an address that had
already connected at the TCP level, racing or not, ended the whole
attempt instead of trying the others, the same regression apache#936 fixed for
the classic client. Adds a SessionValidator hook run on every connected
session before it is accepted, shared by the sequential path and the
race's post-win fallback, mirroring DefaultHttpClientConnectionOperator's
connectSequentially. A deterministic peer-certificate failure stays
final on every path, since the same certificate would be presented on
the remaining addresses too.

Hardens cancellation around the new fallback attempts: executeNext()
checks future.isDone() at both its entry points, under a single
ReentrantLock per connectSequentially() run shared across all its
attempts, so a same-thread reentrant rejection and a cross-thread one
can never race on which attempt is tracked. Race's own six synchronized
blocks are converted the same way. A TlsStrategy that reports an outcome
and then throws is a no-op on the second signal instead of
double-advancing the fallback.

A cancel can still be lost underneath this, in httpcore5:
SingleCoreIOReactor#processConnectionRequest initiates the connect
before assigning the IOSessionRequest a closeable, and never assigns
one at all when the connect completes immediately, so a cancel()
landing in that window closes nothing. A separate, narrower
check-then-set race in ComplexFuture#setDependency is also unclosed.
Both belong in httpcore5, out of scope here; an HTTPCORE ticket will
follow. TestHappyEyeballsTlsFallbackAsync's
cancelDuringFallbackAfterRealTlsFailure_abortsPendingAttempt hits that
window often enough on loopback to be unusable as written, independent
of the happyEyeballs parameter, and is disabled until it's fixed.

TestHttpAsyncMinimalTlsHandshake.testTlsHandshakeFailure is pinned to a
literal address: "localhost" may resolve to both 127.0.0.1 and ::1, and
a TLS failure is no longer necessarily final for the last-tried address.
@arturobernalg
arturobernalg force-pushed the fix-tls-fallback-happy-eyeballs branch from 2577fc8 to d7c7e30 Compare December 2, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants