Uploaded image for project: 'HttpComponents HttpCore'
  1. HttpComponents HttpCore
  2. HTTPCORE-746

Deadlock with Java Virtual Threads

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 4.4.16
    • Stuck
    • HttpCore
    • openjdk version "20.0.1" 2023-04-18
      archlinux

    Description

      Virtual Threads 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 because it is in a  synchronized block 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!

      Attachments

        Activity

          People

            Unassigned Unassigned
            marsqing marsqing
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0h
                0h
                Logged:
                Time Spent - 2.5h
                2.5h