[
https://issues.apache.org/jira/browse/HTTPCORE-746?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Arturo Bernal resolved HTTPCORE-746.
------------------------------------
Resolution: Fixed
> Deadlock with Java Virtual Threads
> ----------------------------------
>
> Key: HTTPCORE-746
> URL: https://issues.apache.org/jira/browse/HTTPCORE-746
> Project: HttpComponents HttpCore
> Issue Type: Improvement
> Components: HttpCore
> Affects Versions: 4.4.16
> Environment: openjdk version "20.0.1" 2023-04-18
> archlinux
> Reporter: marsqing
> Priority: Minor
> Labels: volunteers-wanted
> Fix For: Stuck
>
> Attachments: LoomWithApacheHttpClientTest.java
>
> Time Spent: 2.5h
> Remaining Estimate: 0h
>
> [Virtual Threads|https://openjdk.org/jeps/444] is expected to be released in
> JDK21 soon. Contrast to traditional 'platform threads', virtual threads will
> usually unmount from platform threads when doing blocking operations. But
> accoring to the doc above, when doing blocking operations in synchronized
> block/method, the carrying platform thread will be pinned and can not carry
> other virtual threads.
>
> This limitation will make the sample in the attachment deadlocked. Because
> all the platform threads add pinned in
> [await|https://github.com/apache/httpcomponents-core/blob/45d8a4cb391f591bb8d380b820437b651435774f/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java#LL391C30-L391C30]
> because it is in a [synchronized
> block|https://github.com/apache/httpcomponents-core/blob/45d8a4cb391f591bb8d380b820437b651435774f/httpcore/src/main/java/org/apache/http/pool/AbstractConnPool.java#L244]
> and no connection is available in the pool. The only virtual thread which
> can release the connection to the pool is waiting for some platform threads
> to carry it. That is the platform thread is waiting for a connection while
> the connection is waiting the platform thread to carry its virtual thread and
> return the connection. Thus a deadlock.
>
> If we replace the synchronized above with a ReentrantLock, no thead will be
> pinned and no deadlock will occur. Accoring to the doc above, the limitation
> may be removed in future JDK versions. But before that, we may need to
> replace synchronized with some locks. Do we have any related plan? Thanks!
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]