Uploaded image for project: 'Commons Pool'
  1. Commons Pool
  2. POOL-149

A serious concurrent bug can cause resource leak when Pool exhausted and borrowed objects are invalid

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.5, 1.5.1, 1.5.2
    • Fix Version/s: 1.5.3
    • Labels:
      None

      Description

      This bug will happen when the pool is in exhausted state and the borrowed object are invalid.

      Let's go through a simple scenario:
      1)A GenericObjectPool with _maxActive==1, whenExhaustedAction==WHEN_EXHAUSTED_BLOCK
      2)Two threads using that pool, called thread1 and thread2

      Here is error path:
      1)thread1 calls pool.borrowObject() to get the object out of the pool
      //now the pool is exhausted
      2)thread2 calls pool.borrowObject(), adds a new latch to the _allocationQueue, but before it enters the synchronized block for WHEN_EXHAUSTED_BLOCK(GenericObjectPool line 1099 revision 806215), context-switch happens
      3)thread1 checks the object from pool, and decides to invalidate it. So it calls pool.invalidateObject(), which calls allocate(), then calls latch.notify(), but currently no thread is waiting on this latch.(thread2 has not enter the wait synchronized block yet).
      4)Then thread2 will wait there for ever.(it just missed the notify)

        Attachments

        1. BugTest.java
          3 kB
          shuyang.zhou

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              shuyang.zhou shuyang.zhou
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: