1. OpenJPA
  2. OPENJPA-913

A deadlock issue happens when DirtyListener is used


    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2.0
    • Fix Version/s: 1.1.1, 2.0.0-M2
    • Component/s: kernel
    • Labels:
    • Environment:
      Linux x86


      A deadlock issue happens when OpenJPA entity manager is
      concurrently called and DirtyListener is used and
      DirtyListener.beforeDirty calls an entity manager related
      operation. To call OpenJPA entity manager concurrently,
      we need to define openjpa.MulthThreaded option as true.

      Following is test scenario.

      1. Thread A calls entityMangaer.refresh() repeatedly.
      In refresh() method, entityManager acquires BrokerImpl
      lock. And then, entityManager acquires LifecycleEventManager
      lock to call lifecycle callback.
      2. Thread B calls persistedObject.getAItems() (getting
      collection items).
      3. In enhanced getItems() method, entityManager tries
      to mark it as "dirty". Before marking, callback listener
      DirtyListener.beforeDirty is called. In this point,
      LifecycleEventManager lock is acquired without acquiring
      BrokerImpl lock.
      4. In the testcase, beforeDirty calls persistedObject.getAItems().
      And then, entity manager tries to acquire BrokerImpl lock.
      But, sometimes BrokerImpl lock is already acquired by Thread B.
      So, a deadlock issue happens. deadlock stack is as follows.

      [java] "Thread-1" prio=1 tid=0x09e98b28 nid=0x7fcc waiting on condition [0xb15f3000..0xb15f4130]
      [java] at sun.misc.Unsafe.park(Native Method)
      [java] at java.util.concurrent.locks.LockSupport.park(
      [java] at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(
      [java] at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(
      [java] at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(
      [java] at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(
      [java] at java.util.concurrent.locks.ReentrantLock.lock(
      [java] at org.apache.openjpa.kernel.BrokerImpl.lock(
      [java] at org.apache.openjpa.kernel.BrokerImpl.beginOperation(
      [java] at org.apache.openjpa.kernel.BrokerImpl.isActive(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.beforeRead(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.accessingField(
      [java] at model.A.getAItems(
      [java] at model.ADirtyListener.beforeDirty(
      [java] at org.apache.openjpa.event.LifecycleEventManager.fireEvent(
      [java] at org.apache.openjpa.event.LifecycleEventManager.fireEvent(
      [java] - locked <0x51b4e4b0> (a org.apache.openjpa.event.LifecycleEventManager)
      [java] at org.apache.openjpa.kernel.BrokerImpl.fireLifecycleEvent(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.fireLifecycleEvent(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.dirty(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.dirty(
      [java] at org.apache.openjpa.util.Proxies.dirty(
      [java] at org.apache.openjpa.util.ProxyCollections.beforeAdd(
      [java] at$util$HashSet$proxy.add(Unknown Source)
      [java] at business.Test$
      [java] at

      [java] "Thread-0" prio=1 tid=0x09e9d010 nid=0x7fcb waiting for monitor entry [0xb1674000..0xb1674db0]
      [java] at org.apache.openjpa.event.LifecycleEventManager.fireEvent(
      [java] - waiting to lock <0x51b4e4b0> (a org.apache.openjpa.event.LifecycleEventManager)
      [java] at org.apache.openjpa.kernel.BrokerImpl.fireLifecycleEvent(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.fireLifecycleEvent(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.clearFields(
      [java] at org.apache.openjpa.kernel.StateManagerImpl.beforeRefresh(
      [java] at org.apache.openjpa.kernel.BrokerImpl.refreshInternal(
      [java] at org.apache.openjpa.kernel.BrokerImpl.refresh(
      [java] at org.apache.openjpa.kernel.DelegatingBroker.refresh(
      [java] at org.apache.openjpa.persistence.EntityManagerImpl.refresh(
      [java] at business.Test$
      [java] at

      Intially the problem is reproduced on OpenJPA 1.x. But,
      I verified the problem could be reproduced with latest
      OpenJPA head.

        5.26 MB
        Hiroki Tateno
      2. proposed-fix.patch
        0.9 kB
        Hiroki Tateno



          • Assignee:
            Hiroki Tateno
          • Votes:
            0 Vote for this issue
            0 Start watching this issue


            • Created: