Skip to content

Close selectors with the classic Unix domain socket - #3339

Open
qq2514568380 wants to merge 16 commits into
apache:masterfrom
qq2514568380:fix-3334-close-socket-selectors
Open

qq2514568380 wants to merge 16 commits into
apache:masterfrom
qq2514568380:fix-3334-close-socket-selectors

Conversation

@qq2514568380

Copy link
Copy Markdown

Summary

The classic Unix-domain socket adapter opens separate selectors for its input and output wrappers. The connection close path can bypass both wrappers, which leaves their selectors open.

Create at most one wrapper per direction, close both selectors when the socket or either stream closes, and clean up a selector if registration fails.

Validation

Added regression cases for socket close and stream close. Both verify the two selectors and the channel are closed. Static diff checks passed. The tests were not run locally.

Fixes #3334.

Prepared with Codex assistance.

arturobernalg and others added 15 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]>
@Override
protected void close() throws IOException {
channel.close();
protected synchronized void close() throws IOException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qq2514568380 We do explicit locking with Lock instead of synchronized everywhere in the library. Could you please make your changes consistent with the rest of the codebase.

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.

Close the selectors owned by the classic Unix-domain socket adapter

4 participants