Integrated: 8372198: Avoid closing PlainHttpConnection while holding a lock

Daniel Fuchs dfuchs at openjdk.org
Thu Nov 27 17:58:59 UTC 2025


On Thu, 20 Nov 2025 13:10:53 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

> An experimental change to SelectorManager::shutdown unveiled 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.
> 
> This PR was recreated due to a bad merge pushed to https://github.com/openjdk/jdk/pull/28421

This pull request has now been integrated.

Changeset: 8a0672c8
Author:    Daniel Fuchs <dfuchs at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/8a0672c819e09a16c30fbdf58dc2b81f50958da4
Stats:     431 lines in 4 files changed: 406 ins; 9 del; 16 mod

8372198: Avoid closing PlainHttpConnection while holding a lock

Reviewed-by: djelinski, jpai, vyazici

-------------

PR: https://git.openjdk.org/jdk/pull/28430


More information about the net-dev mailing list