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/3339a65f Tree: http://git-wip-us.apache.org/repos/asf/ode/tree/3339a65f Diff: http://git-wip-us.apache.org/repos/asf/ode/diff/3339a65f Branch: refs/heads/ode-1.3.x Commit: 3339a65f275c259bbf847f45a4074876154c4fcf Parents: 9760c4f Author: sathwik <[email protected]> Authored: Tue Aug 18 13:06:16 2015 +0530 Committer: sathwik <[email protected]> Committed: Tue Aug 18 13:06:16 2015 +0530 ---------------------------------------------------------------------- .../org/apache/ode/store/ProcessStoreImpl.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ode/blob/3339a65f/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 9a4c8d8..302c61c 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 @@ -193,7 +193,7 @@ public class ProcessStoreImpl implements ProcessStore { // Override the package name if given from the parameter du.setName(duName); } - + long version; if (autoincrementVersion || du.getStaticVersion() == -1) { // Process and DU use a monotonically increased single version number by default. @@ -203,12 +203,11 @@ public class ProcessStoreImpl implements ProcessStore { //we need to reset the current version thread local value. _currentVersion.set(null); } - } else { version = du.getStaticVersion(); } du.setVersion(version); - + try { du.compile(); } catch (CompilationException ce) { @@ -300,7 +299,6 @@ public class ProcessStoreImpl implements ProcessStore { newDao.setProperty(prop.getKey(), DOMUtils.domToString(prop.getValue())); } deployed.add(pc.getProcessId()); - } catch (Throwable e) { String errmsg = "Error persisting deployment record for " + pc.getProcessId() + "; process will not be available after restart!"; @@ -311,8 +309,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() @@ -320,14 +319,21 @@ 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); + } finally { + if(readLockHeld) + _rw.readLock().unlock(); } return deployed; + } /**
