Skip to content

Conversation

@dfuch
Copy link
Member

@dfuch dfuch commented Nov 20, 2025

An experimental change to SelectorManager::shutdown unveil a potential deadlock between the SelectorManager thread trying to stop the HttpClientImpl, and an executor thread concurrently trying to return a connection to the pool.

The issue seems to be caused by the ConnectionPool::returnToPool trying to close the returned connection when stopping, while holding the ConnectionPool state lock, and the SelectorManager thread trying to close a pooled connection, holding the connection stateLock and trying to close the channel, which caused the CleanupTrigger to fire and attempt to remove the connection from the pool.

This problem was observed once with the java/net/httpclient/ThrowingSubscribersAsLimitingAsync.java test.

To avoid the problem, the proposed fix is to wait until the ConnectionPool::stateLock has been released before actually closing the connection, and to wait until the PlainHttpConnection::stateLock has been released before actually closing the channel. Indeed, there should be no need to close those while holding the lock.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Integration blocker

 ⚠️ Dependency #28395 must be integrated first

Warnings

 ⚠️ Patch contains a binary file (src/java.base/share/classes/jdk/internal/icu/impl/data/icudata/nfc.nrm)
 ⚠️ Patch contains a binary file (src/java.base/share/classes/jdk/internal/icu/impl/data/icudata/ubidi.icu)
 ⚠️ Patch contains a binary file (src/java.base/share/classes/jdk/internal/icu/impl/data/icudata/uprops.icu)

Issue

  • JDK-8372198: Avoid closing PlainHttpConnection while holding a lock (Bug - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/28421/head:pull/28421
$ git checkout pull/28421

Update a local copy of the PR:
$ git checkout pull/28421
$ git pull https://git.openjdk.org/jdk.git pull/28421/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 28421

View PR using the GUI difftool:
$ git pr show -t 28421

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/28421.diff

Using Webrev

Link to Webrev Comment

minborg and others added 30 commits November 18, 2025 12:20
8371882: Improve documentation for JEP 526: Lazy Constants

Reviewed-by: jvernee, mcimadamore
….java should check ability to create links

Reviewed-by: alanb, jpai
…scribeConstable

Reviewed-by: psandoz, jvernee
8346947: Update ICU4J to Version 78.1

Reviewed-by: joehw
…ointer to non-trivially copyable type

Co-authored-by: Ioi Lam <iklam@openjdk.org>
Reviewed-by: iklam, asmehra
Reviewed-by: smarks, ogillespie
Reviewed-by: stefank, tschatzl
…and switch (Fourth Preview)

Reviewed-by: jlahoda
…embler::patch_barrier_relocation

Reviewed-by: aph
…rGenerator::generate_native_entry

Reviewed-by: aph, shade
@bridgekeeper
Copy link

bridgekeeper bot commented Nov 20, 2025

👋 Welcome back dfuchs! A progress list of the required criteria for merging this PR into pr/28395 will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 20, 2025

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk bot added the net net-dev@openjdk.org label Nov 20, 2025
@openjdk
Copy link

openjdk bot commented Nov 20, 2025

@dfuch The following label will be automatically applied to this pull request:

  • net

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@dfuch
Copy link
Member Author

dfuch commented Nov 20, 2025

/issue 8372198

@openjdk
Copy link

openjdk bot commented Nov 20, 2025

@dfuch The issue 8372198 was not found in the JDK project - make sure you have entered it correctly.
As there were validation problems, no additional issues will be added to the list of solved issues.

@dfuch dfuch changed the title 8372198: Avoid closing PlainHttpConnection while holding a lock 8372198: Grr Avoid closing PlainHttpConnection while holding a lock Nov 20, 2025
@dfuch dfuch changed the title 8372198: Grr Avoid closing PlainHttpConnection while holding a lock 8372198: Avoid closing PlainHttpConnection while holding a lock Nov 20, 2025
@dfuch dfuch changed the title 8372198: Avoid closing PlainHttpConnection while holding a lock : Avoid closing PlainHttpConnection while holding a lock Nov 20, 2025
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 20, 2025
@dfuch dfuch changed the title : Avoid closing PlainHttpConnection while holding a lock 8372198: Avoid closing PlainHttpConnection while holding a lock Nov 20, 2025
@mlbridge
Copy link

mlbridge bot commented Nov 20, 2025

Webrevs

@openjdk
Copy link

openjdk bot commented Nov 20, 2025

⚠️ @dfuch This pull request contains merges that bring in commits not present in the target repository. Since this is not a "merge style" pull request, these changes will be squashed when this pull request in integrated. If this is your intention, then please ignore this message. If you want to preserve the commit structure, you must change the title of this pull request to Merge <project>:<branch> where <project> is the name of another project in the OpenJDK organization (for example Merge jdk:master).

@openjdk openjdk bot added javadoc javadoc-dev@openjdk.org security security-dev@openjdk.org hotspot hotspot-dev@openjdk.org build build-dev@openjdk.org nio nio-dev@openjdk.org client client-libs-dev@openjdk.org core-libs core-libs-dev@openjdk.org compiler compiler-dev@openjdk.org i18n i18n-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org labels Nov 20, 2025
@openjdk
Copy link

openjdk bot commented Nov 20, 2025

@dfuch build, client, compiler, core-libs, hotspot, i18n, javadoc, nio, security, shenandoah have been added to this pull request based on files touched in new commit(s).

@dfuch dfuch closed this Nov 20, 2025
@dfuch
Copy link
Member Author

dfuch commented Nov 20, 2025

Something went wrong when I tried to merge the main PR branch in the dependent PR branch. I'm going to withdraw this PR and start again.

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

Labels

build build-dev@openjdk.org client client-libs-dev@openjdk.org compiler compiler-dev@openjdk.org core-libs core-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org i18n i18n-dev@openjdk.org javadoc javadoc-dev@openjdk.org net net-dev@openjdk.org nio nio-dev@openjdk.org rfr Pull request is ready for review security security-dev@openjdk.org shenandoah shenandoah-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.