Skip to content

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

Open
arturobernalg wants to merge 19 commits into
apache:masterfrom
arturobernalg:fix-tls-fallback-happy-eyeballs
Open

arturobernalg wants to merge 19 commits 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 and others added 14 commits November 25, 2026 18:46
No notifications block meant issue events defaulted to [email protected]
via the Apache Git Service. Harmless at normal volume, but the Jira
Issues migration (INFRA-28579) is about to import 2347 issues here,
which would flood the list. Point issues at [email protected]
instead, same pattern apache/maven and apache/opennlp use after their
own Jira migrations.
The ASF Git Service's .asf.yaml validator rejected [email protected]:
notifications targets must be the project's real @httpcomponents.apache.org
list, not the hc.apache.org vanity domain used on the website/mail links.
Neither [email protected] nor [email protected]
validated. Infra is creating [email protected] instead
(INFRA-28579, simpler than a new list under httpcomponents.apache.org).
Don't merge until confirmed created.
The mapping was fixed in apache/infrastructure-asfyaml#152 (httpcomponents
-> hc), but issue notifications still went to dev@ after the merge. No
content change, just a fresh push to .asf.yaml to force the Git Service
to re-evaluate the notifications block.
Per Infra (Bob), force a real value-diff push to .asf.yaml so the Git
Service fully reprocesses notifications::issues end to end, rather
than a no-op comment-only re-save. Restored to [email protected]
in a follow-up commit.
Second half of the revert/restore cycle Infra (Bob) asked for, to force
the Git Service to fully reprocess notifications::issues end to end.
Define INTERLEAVE as no-bias and align tests and debug output.
Add manual gated IT to dump DEFAULT vs INTERLEAVE results.
Expand unit coverage for scope mapping and core RFC comparison rules.
…ults.

Tighten resolver semantics and filtering for HTTP/TCP connect targets.
Races connection attempts across a host's resolved addresses instead
of trying them strictly sequentially: first address immediately, each
next one after a configurable delay (250ms default) unless an earlier
one fails first, in which case the next address starts at the RFC
8305 Section 5 minimum spacing (10ms). First success wins; the rest
are cancelled or closed. An attempt cancelled from outside the race is
treated like a failure so the future is never left pending forever.

A winning session can be selected by the race at the same moment the
caller cancels the outer Future directly. ComplexFuture#completed then
returns false; close the session instead of silently dropping it.

Opt-in, off by default; disabled behavior is unchanged.
…ient

Replaces the one-thread-per-address, sleep-based stagger with a single
dispatcher that starts the first address immediately and waits up to
the connection attempt delay for an outstanding attempt to finish
before starting the next; on a failure it advances immediately, at the
RFC 8305 minimum spacing (10ms), instead of waiting out the full delay.
No worker thread ever sleeps a delay itself, bounding concurrency to
the number of resolved addresses actually in flight.

Socket registration goes through a small atomic registry instead of a
bare reference: deciding a winner and a worker registering its socket
can happen at the same instant, and whichever runs second closes the
socket, so nothing registered around that moment survives open
regardless of timing. shutdownNow() alone cannot abort a blocking
Socket#connect; closing the socket is what actually does that, on
every exit path (winner found, every address failed, or interrupted)
via one cleanup call in a finally block.

An interruption during the minimum-spacing wait is now propagated
instead of swallowed, aborting the race immediately like interruption
anywhere else in it. Racing is skipped in favor of the existing
sequential path when a specific, non-ephemeral local port is
requested, since binding several attempts to it concurrently would
trade a real connect failure for a spurious bind conflict.

Public, blocking connect() behavior, TLS, SOCKS and local binding are
otherwise unchanged.
Since the challenge parsing was reworked, a single malformed
WWW-Authenticate or Proxy-Authenticate header causes all challenges in
the response to be discarded, so a valid Basic or Digest challenge in
another header is no longer used and the 401 is returned as is. Before
that change only the malformed header was skipped.

The empty map returned in that case is also immutable, so a response
that carries Authentication-Info together with a malformed challenge
header fails with UnsupportedOperationException.

Parse each header separately again and skip only the ones that fail.
Bumps the all group with 10 updates:

| Package | From | To |
| --- | --- | --- |
| [org.conscrypt:conscrypt-openjdk-uber](https://github.com/google/conscrypt) | `2.8.0` | `2.10.0` |
| [org.junit:junit-bom](https://github.com/junit-team/junit-framework) | `5.14.4` | `5.14.5` |
| [com.github.luben:zstd-jni](https://github.com/luben/zstd-jni) | `1.5.7-25` | `1.6.0-1` |
| [io.micrometer:micrometer-core](https://github.com/micrometer-metrics/micrometer) | `1.17.2` | `1.18.0` |
| [io.micrometer:micrometer-observation](https://github.com/micrometer-metrics/micrometer) | `1.17.2` | `1.18.0` |
| [io.micrometer:micrometer-registry-prometheus](https://github.com/micrometer-metrics/micrometer) | `1.17.2` | `1.18.0` |
| [io.micrometer:micrometer-tracing](https://github.com/micrometer-metrics/tracing) | `1.7.2` | `1.8.0` |
| [io.micrometer:micrometer-tracing-bridge-otel](https://github.com/micrometer-metrics/tracing) | `1.7.2` | `1.8.0` |
| [io.opentelemetry:opentelemetry-bom](https://github.com/open-telemetry/opentelemetry-java) | `1.67.0` | `1.68.0` |
| org.apache.maven:apache-maven | `3.10.0` | `3.10.2` |


Updates `org.conscrypt:conscrypt-openjdk-uber` from 2.8.0 to 2.10.0
- [Release notes](https://github.com/google/conscrypt/releases)
- [Commits](google/conscrypt@2.8.0...2.10.0)

Updates `org.junit:junit-bom` from 5.14.4 to 5.14.5
- [Release notes](https://github.com/junit-team/junit-framework/releases)
- [Commits](junit-team/junit-framework@r5.14.4...r5.14.5)

Updates `com.github.luben:zstd-jni` from 1.5.7-25 to 1.6.0-1
- [Commits](luben/zstd-jni@v1.5.7-25...v1.6.0-1)

Updates `io.micrometer:micrometer-core` from 1.17.2 to 1.18.0
- [Release notes](https://github.com/micrometer-metrics/micrometer/releases)
- [Commits](micrometer-metrics/micrometer@v1.17.2...v1.18.0)

Updates `io.micrometer:micrometer-observation` from 1.17.2 to 1.18.0
- [Release notes](https://github.com/micrometer-metrics/micrometer/releases)
- [Commits](micrometer-metrics/micrometer@v1.17.2...v1.18.0)

Updates `io.micrometer:micrometer-registry-prometheus` from 1.17.2 to 1.18.0
- [Release notes](https://github.com/micrometer-metrics/micrometer/releases)
- [Commits](micrometer-metrics/micrometer@v1.17.2...v1.18.0)

Updates `io.micrometer:micrometer-observation` from 1.17.2 to 1.18.0
- [Release notes](https://github.com/micrometer-metrics/micrometer/releases)
- [Commits](micrometer-metrics/micrometer@v1.17.2...v1.18.0)

Updates `io.micrometer:micrometer-registry-prometheus` from 1.17.2 to 1.18.0
- [Release notes](https://github.com/micrometer-metrics/micrometer/releases)
- [Commits](micrometer-metrics/micrometer@v1.17.2...v1.18.0)

Updates `io.micrometer:micrometer-tracing` from 1.7.2 to 1.8.0
- [Release notes](https://github.com/micrometer-metrics/tracing/releases)
- [Commits](micrometer-metrics/tracing@v1.7.2...v1.8.0)

Updates `io.micrometer:micrometer-tracing-bridge-otel` from 1.7.2 to 1.8.0
- [Release notes](https://github.com/micrometer-metrics/tracing/releases)
- [Commits](micrometer-metrics/tracing@v1.7.2...v1.8.0)

Updates `io.micrometer:micrometer-tracing-bridge-otel` from 1.7.2 to 1.8.0
- [Release notes](https://github.com/micrometer-metrics/tracing/releases)
- [Commits](micrometer-metrics/tracing@v1.7.2...v1.8.0)

Updates `io.opentelemetry:opentelemetry-bom` from 1.67.0 to 1.68.0
- [Release notes](https://github.com/open-telemetry/opentelemetry-java/releases)
- [Changelog](https://github.com/open-telemetry/opentelemetry-java/blob/main/CHANGELOG.md)
- [Commits](open-telemetry/opentelemetry-java@v1.67.0...v1.68.0)

Updates `org.apache.maven:apache-maven` from 3.10.0 to 3.10.2

---
updated-dependencies:
- dependency-name: org.conscrypt:conscrypt-openjdk-uber
  dependency-version: 2.10.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: org.junit:junit-bom
  dependency-version: 5.14.5
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
- dependency-name: com.github.luben:zstd-jni
  dependency-version: 1.6.0-1
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-core
  dependency-version: 1.18.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-observation
  dependency-version: 1.18.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-registry-prometheus
  dependency-version: 1.18.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-observation
  dependency-version: 1.18.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-registry-prometheus
  dependency-version: 1.18.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-tracing
  dependency-version: 1.8.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-tracing-bridge-otel
  dependency-version: 1.8.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.micrometer:micrometer-tracing-bridge-otel
  dependency-version: 1.8.0
  dependency-type: direct:development
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: io.opentelemetry:opentelemetry-bom
  dependency-version: 1.68.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: all
- dependency-name: org.apache.maven:apache-maven
  dependency-version: 3.10.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: all
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [actions/setup-java](https://github.com/actions/setup-java) from 5.6.0 to 6.3.0.
- [Release notes](https://github.com/actions/setup-java/releases)
- [Commits](actions/setup-java@v5.6.0...v6.3.0)

---
updated-dependencies:
- dependency-name: actions/setup-java
  dependency-version: 6.3.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
@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.

Aayush10016 and others added 3 commits December 4, 2026 11:11
RFC 8187 ext-value is a token, not a quoted-string. Express/multer
(busboy) drops the file part and Flask (Werkzeug) returns the literal
quoted string as the file name when filename* is quoted.
@ok2c ok2c added the 5.8.x 5.8 release series label Dec 5, 2026
Hsnmohd and others added 2 commits December 5, 2026 10:12
… (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 d7c7e30 to f00cd97 Compare December 5, 2026 09:57
@arturobernalg

Copy link
Copy Markdown
Member Author

My bad, slip on my end — already fixed. Rebased on current master; synchronized is gone from MultihomeIOSessionRequester, ReentrantLock everywhere now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5.8.x 5.8 release series

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants