ODE-1026: Acquire readLock while firing events to avoid deadlock

Project: http://git-wip-us.apache.org/repos/asf/ode/repo
Commit: http://git-wip-us.apache.org/repos/asf/ode/commit/b6b655d7
Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/b6b655d7
Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/b6b655d7

Branch: refs/heads/master
Commit: b6b655d7a18ce305c5260c92f6d3c0010a613b88
Parents: 97239d0
Author: sathwik <[email protected]>
Authored: Tue Aug 18 15:50:24 2015 +0530
Committer: sathwik <[email protected]>
Committed: Tue Aug 18 15:50:24 2015 +0530

----------------------------------------------------------------------
 .../main/java/org/apache/ode/store/ProcessStoreImpl.java | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ode/blob/b6b655d7/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
----------------------------------------------------------------------
diff --git 
a/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java 
b/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
index fabd531..ba911a7 100644
--- a/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
+++ b/bpel-store/src/main/java/org/apache/ode/store/ProcessStoreImpl.java
@@ -308,7 +308,9 @@ public class ProcessStoreImpl implements ProcessStore {
 
         });
 
-        // We want the events to be fired outside of the bounds of the 
writelock.
+
+        _rw.readLock().lock();
+        boolean readLockHeld = true;
         try {
             for (ProcessConfImpl process : processes) {
                 fireEvent(new 
ProcessStoreEvent(ProcessStoreEvent.Type.DEPLOYED, process.getProcessId(), 
process.getDeploymentUnit()
@@ -316,11 +318,18 @@ public class ProcessStoreImpl implements ProcessStore {
                 fireStateChange(process.getProcessId(), process.getState(), 
process.getDeploymentUnit().getName());
             }
         } catch (Exception e) {
+            //need to unlock as undeploy operation will need a writeLock
+            _rw.readLock().unlock();
+            readLockHeld = false;
+
             // A problem at that point means that engine deployment failed, we 
don't want the store to keep the du
             __log.warn("Deployment failed within the engine, store undeploying 
process.", e);
             undeploy(deploymentUnitDirectory);
             if (e instanceof ContextException) throw (ContextException) e;
             else throw new ContextException("Deployment failed within the 
engine. " + e.getMessage(), e);
+        } finally {
+            if(readLockHeld)
+                _rw.readLock().unlock();
         }
 
         return deployed;

Reply via email to