<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hi Edson,<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Our emails just crossed paths.&nbsp; Yes, I believe that I can
reproduce this.&nbsp; I&#8217;ll try to turn this around quickly.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Ed<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
rules-dev-bounces@lists.jboss.org [mailto:rules-dev-bounces@lists.jboss.org] <b>On
Behalf Of </b>Edson Tirelli<br>
<b>Sent:</b> Wednesday, November 04, 2009 5:06 PM<br>
<b>To:</b> Rules Dev List<br>
<b>Subject:</b> Re: [rules-dev] Deadlock in the Drools core - Drools 5.0 - any
suggestions for resolution?<o:p></o:p></span></p>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal style='margin-bottom:12.0pt'><br>
&nbsp;&nbsp; Edward,<br>
<br>
&nbsp;&nbsp; Are you able to provide us with a test case? that would help us
ensure we fix this and prevent future regressions.<br>
<br>
&nbsp;&nbsp; Thanks,<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Edson<o:p></o:p></p>

<div>

<p class=MsoNormal>2009/11/4 Edward Archibald &lt;<a
href="mailto:edward.archibald@continuent.com">edward.archibald@continuent.com</a>&gt;<o:p></o:p></p>

<p class=MsoNormal>Hi Greg,<br>
<br>
Thanks for the post. &nbsp;I'll give this a shot. &nbsp;Turns out that I can
reproduce the issue often enough that I'll be able to see if this simple change
resolves it.<br>
<br>
Regards,<br>
<br>
Edward<br>
<br>
________________________________________<br>
From: <a href="mailto:rules-dev-bounces@lists.jboss.org">rules-dev-bounces@lists.jboss.org</a>
[<a href="mailto:rules-dev-bounces@lists.jboss.org">rules-dev-bounces@lists.jboss.org</a>]
On Behalf Of Greg Barton [<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>]<br>
Sent: Tuesday, November 03, 2009 9:43 PM<br>
To: Rules Dev List<br>
Subject: Re: [rules-dev] Deadlock in the Drools core - Drools 5.0 - any suggestions
for resolution?<o:p></o:p></p>

<div>

<div>

<p class=MsoNormal><br>
Well, I'm not sure how to avoid the deadlock without changing the drools
codebase. &nbsp;I was, however, able to change the type of
AbstractWorkingMemory.actionQueue to java.util.concurrent.ConcurrentLinkedQueue
and remove the synchronization over the queue with no apparent ill effects.
(Two tests failed for drools-core, but they failed whether the change was made
or not.) &nbsp;Also I don't like the fact that the current code synchronizes on
actionQueue, but then exposes it outside the class through the getActionQueue()
method, where access can be unsynchronized. &nbsp;Changing it to
ConcurrentLinkedQueue makes it safe to expose externally. (Not to mention that
the lock can be stolen externally with the current code.)<br>
<br>
diff attached. &nbsp;If you can run drools compiled from trunk, apply the diff
and see if it resolves the deadlock. &nbsp;If it does it's up to the drools
devs as to whether the change should be made. &nbsp;I'm just hacking about. :P<br>
<br>
--- On Tue, 11/3/09, Edward Archibald &lt;<a
href="mailto:edward.archibald@continuent.com">edward.archibald@continuent.com</a>&gt;
wrote:<br>
<br>
&gt; From: Edward Archibald &lt;<a href="mailto:edward.archibald@continuent.com">edward.archibald@continuent.com</a>&gt;<br>
&gt; Subject: [rules-dev] Deadlock in the Drools core - Drools 5.0 - any suggestions
for resolution?<br>
&gt; To: &quot;<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>&quot;
&lt;<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a>&gt;<br>
&gt; Date: Tuesday, November 3, 2009, 9:41 PM<br>
&gt;<br>
&gt; I found the following deadlock which is, apparently, due to<br>
&gt; the concurrent execution<br>
&gt; of a task for a 'delayed' rule with a concurrently<br>
&gt; executing application thread attempting to get access to a<br>
&gt; 'global'. &nbsp;Any recommendations for avoiding this type<br>
&gt; of deadlock besides not using rules with 'duration()' etc.<br>
&gt; which cause asynchronous execution with respect to my main<br>
&gt; application thread?<br>
&gt;<br>
&gt; This problem is somewhat difficult to reproduce on demand<br>
&gt; but it does come up frequently when the 'delayed' rule<br>
&gt; &quot;DETECT MONITORING HAS STOPPED&quot; is activated as a result of<br>
&gt; the trigger conditions.<br>
&gt;<br>
&gt;
===================================================================================<br>
&gt;<br>
&gt; This thread, my application's EnterprisePolicyManager<br>
&gt; thread, is attempting to get access to a global, policyMgr,<br>
&gt; and is waiting for<br>
&gt; the 'lock.lock' on RetooStatefulSession<br>
&gt;<br>
&gt; It owns the 'ReteooStatefulSession.actionQueue'<br>
&gt; and is waiting for the ReteooStatefulSession.lock.lock<br>
&gt;<br>
&gt; owns: java.util.LinkedList&lt;E&gt;&nbsp; (id=207)<br>
&gt; waited by: Thread [pool-3-thread-1] (Suspended)<br>
&gt; owns:<br>
&gt; com.continuent.tungsten.cluster.manager.rules.engine.RulesEngine<br>
&gt; (id=208)<br>
&gt; sun.misc.Unsafe.park(boolean, long) line: not available<br>
&gt; [native method] [local variables unavailable]<br>
&gt; java.util.concurrent.locks.LockSupport.park() line: 118<br>
&gt; [local variables unavailable]<br>
&gt;
java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt()<br>
&gt; line: 681 [local variables unavailable]<br>
&gt; java.util.concurrent.locks.ReentrantLock$NonfairSync(java.util.concurrent.locks.AbstractQueuedSynchronizer).acquireQueued(java.util.concurrent.locks.AbstractQueuedSynchronizer$Node,<br>
&gt; int) line: 711<br>
&gt;
java.util.concurrent.locks.ReentrantLock$NonfairSync(java.util.concurrent.locks.AbstractQueuedSynchronizer).acquire(int)<br>
&gt; line: 1041<br>
&gt; java.util.concurrent.locks.ReentrantLock$NonfairSync.lock()<br>
&gt; line: 184 [local variables unavailable]<br>
&gt; java.util.concurrent.locks.ReentrantLock.lock() line: 256<br>
&gt; [local variables unavailable]<br>
&gt; org.drools.reteoo.ReteooStatefulSession(org.drools.common.AbstractWorkingMemory).getGlobal(java.lang.String)<br>
&gt; line: 587<br>
&gt;
com.continuent.tungsten.cluster.manager.policy.Rule_IF_IN_MAINTENANCE_MODE__CONSUME_ALL_NOTIFICATIONS_0Eval0Invoker.evaluate(org.drools.spi.Tuple,<br>
&gt; org.drools.rule.Declaration[], org.drools.WorkingMemory,<br>
&gt; java.lang.Object) line: not available<br>
&gt; org.drools.rule.EvalCondition.isAllowed(org.drools.spi.Tuple,<br>
&gt; org.drools.WorkingMemory, java.lang.Object) line: 117<br>
&gt; org.drools.reteoo.EvalConditionNode.assertLeftTuple(org.drools.reteoo.LeftTuple,<br>
&gt; org.drools.spi.PropagationContext,<br>
&gt; org.drools.common.InternalWorkingMemory) line: 180<br>
&gt;
org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(org.drools.spi.PropagationContext,<br>
&gt; org.drools.common.InternalWorkingMemory,<br>
&gt; org.drools.reteoo.LeftTuple) line: 117<br>
&gt;
org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(org.drools.reteoo.LeftTuple,<br>
&gt; org.drools.reteoo.RightTuple,<br>
&gt; org.drools.spi.PropagationContext,<br>
&gt; org.drools.common.InternalWorkingMemory, boolean) line: 28<br>
&gt;
org.drools.reteoo.JoinNode.assertObject(org.drools.common.InternalFactHandle,<br>
&gt; org.drools.spi.PropagationContext,<br>
&gt; org.drools.common.InternalWorkingMemory) line: 175<br>
&gt; org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(org.drools.common.InternalFactHandle,<br>
&gt; org.drools.spi.PropagationContext,<br>
&gt; org.drools.common.InternalWorkingMemory) line: 42<br>
&gt;
org.drools.reteoo.PropagationQueuingNode$AssertAction.execute(org.drools.reteoo.ObjectSinkPropagator,<br>
&gt; org.drools.common.InternalWorkingMemory) line: 326<br>
&gt;
org.drools.reteoo.PropagationQueuingNode.propagateActions(org.drools.common.InternalWorkingMemory)<br>
&gt; line: 221<br>
&gt;
org.drools.reteoo.PropagationQueuingNode$PropagateAction.execute(org.drools.common.InternalWorkingMemory)<br>
&gt; line: 394<br>
&gt;
org.drools.reteoo.ReteooStatefulSession(org.drools.common.AbstractWorkingMemory).executeQueuedActions()<br>
&gt; line: 1486<br>
&gt;
org.drools.common.NamedEntryPoint.insert(org.drools.common.InternalFactHandle,<br>
&gt; java.lang.Object, org.drools.rule.Rule,<br>
&gt; org.drools.spi.Activation) line: 158<br>
&gt; org.drools.common.NamedEntryPoint.insert(java.lang.Object,<br>
&gt; boolean, boolean, org.drools.rule.Rule,<br>
&gt; org.drools.spi.Activation) line: 122<br>
&gt; org.drools.common.NamedEntryPoint.insert(java.lang.Object)<br>
&gt; line: 80<br>
&gt; com.continuent.tungsten.cluster.manager.rules.engine.RulesEngine.insertFact(com.continuent.tungsten.commons.cluster.resource.notification.NotificationStreamID,<br>
&gt; java.lang.Object, boolean) line: 162<br>
&gt; com.continuent.tungsten.cluster.manager.policy.EnterprisePolicyManager.run()<br>
&gt; line: 249<br>
&gt; java.lang.Thread.run() line: 595<br>
&gt;<br>
&gt; The rule implicated in the above thread is:<br>
&gt;<br>
&gt; rule &quot;IF IN MAINTENANCE MODE, CONSUME ALL NOTIFICATIONS&quot;<br>
&gt; salience 999<br>
&gt; &nbsp; when<br>
&gt; &nbsp; &nbsp; notification : ClusterResourceNotification()<br>
&gt; from entry-point &quot;MONITORING&quot;<br>
&gt; &nbsp; &nbsp; eval(policyMgr.getMode() ==<br>
&gt; ClusterPolicyManagerMode.MAINTENANCE)<br>
&gt; &nbsp; then<br>
&gt; &nbsp; &nbsp; &nbsp;statistics.increment(&quot;IF IN<br>
&gt; MAINTENANCE MODE, CONSUME ALL NOTIFICATIONS&quot;);<br>
&gt; &nbsp; &nbsp; retract(notification);<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; This other thread, apparently a scheduled thread for a rule<br>
&gt; with a 10 second duration,<br>
&gt; is attempting to insert a fact and owns the 'lock.lock' on<br>
&gt; ReteooStatefulSession and<br>
&gt; is waiting for the 'ReteooStatefulSession.actionQueue'.<br>
&gt;<br>
&gt; owns: org.drools.common.DefaultAgenda &nbsp;(id=4046)<br>
&gt; waiting for: java.util.LinkedList&lt;E&gt;&nbsp; (id=207)<br>
&gt;
org.drools.reteoo.ReteooStatefulSession(org.drools.common.AbstractWorkingMemory).executeQueuedActions()<br>
&gt; line: 1480<br>
&gt;
org.drools.reteoo.ReteooStatefulSession(org.drools.common.AbstractWorkingMemory).insert(org.drools.common.InternalFactHandle,<br>
&gt; java.lang.Object, org.drools.rule.Rule,<br>
&gt; org.drools.spi.Activation, org.drools.reteoo.ObjectTypeConf)<br>
&gt; line: 1051<br>
&gt;
org.drools.reteoo.ReteooStatefulSession(org.drools.common.AbstractWorkingMemory).insert(java.lang.Object,<br>
&gt; boolean, boolean, org.drools.rule.Rule,<br>
&gt; org.drools.spi.Activation) line: 1001<br>
&gt; org.drools.base.DefaultKnowledgeHelper.insert(java.lang.Object,<br>
&gt; boolean) line: 114<br>
&gt; org.drools.base.DefaultKnowledgeHelper.insert(java.lang.Object)<br>
&gt; line: 108<br>
&gt;
com.continuent.tungsten.cluster.manager.policy.Rule_DETECT_MONITORING_HAS_STOPPED_0.consequence(org.drools.spi.KnowledgeHelper,<br>
&gt;
com.continuent.tungsten.commons.cluster.resource.notification.DataServerNotification,<br>
&gt; org.drools.FactHandle, java.lang.String,<br>
&gt; org.drools.FactHandle,<br>
&gt; com.continuent.tungsten.cluster.manager.policy.EnterprisePolicyManager,<br>
&gt; org.apache.log4j.Logger) line: not available<br>
&gt;
com.continuent.tungsten.cluster.manager.policy.Rule_DETECT_MONITORING_HAS_STOPPED_0ConsequenceInvoker.evaluate(org.drools.spi.KnowledgeHelper,<br>
&gt; org.drools.WorkingMemory) line: not available<br>
&gt; org.drools.common.DefaultAgenda.fireActivation(org.drools.spi.Activation)<br>
&gt; line: 934<br>
&gt;
org.drools.common.Scheduler$DuractionJob.execute(org.drools.time.JobContext)<br>
&gt; line: 70<br>
&gt; org.drools.time.impl.JDKTimerService$JDKCallableJob.call()<br>
&gt; line: 132<br>
&gt; org.drools.time.impl.JDKTimerService$JDKCallableJob.call()<br>
&gt; line: 110<br>
&gt; java.util.concurrent.FutureTask$Sync.innerRun() line: 269<br>
&gt; java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask&lt;V&gt;(java.util.concurrent.FutureTask&lt;V&gt;).run()<br>
&gt; line: 123<br>
&gt;
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask&lt;V&gt;.access$301(java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask)<br>
&gt; line: 65<br>
&gt;
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask&lt;V&gt;.run()<br>
&gt; line: 168<br>
&gt; java.util.concurrent.ThreadPoolExecutor$Worker.runTask(java.lang.Runnable)<br>
&gt; line: 650<br>
&gt; java.util.concurrent.ThreadPoolExecutor$Worker.run() line:<br>
&gt; 675<br>
&gt; java.lang.Thread.run() line: 595<br>
&gt;<br>
&gt; The rule for this task looks like:<br>
&gt; rule &quot;DETECT MONITORING HAS STOPPED&quot;<br>
&gt; duration(10s)<br>
&gt; salience 1000<br>
&gt; &nbsp; when<br>
&gt; &nbsp; &nbsp; lastNotification :<br>
&gt; DataServerNotification($resourceName : resourceName)<br>
&gt;<br>
&gt; &nbsp; from entry-point &quot;MONITORING&quot;<br>
&gt;<br>
&gt; &nbsp; &nbsp; not (DataServerNotification(resourceName ==<br>
&gt; $resourceName,<br>
&gt;<br>
&gt;<br>
&gt; &nbsp; &nbsp;this after [10s] lastNotification)<br>
&gt;<br>
&gt; &nbsp; from entry-point &quot;MONITORING&quot;)<br>
&gt;<br>
&gt; &nbsp; &nbsp; not (ManagerFailedAlarm(expired == false,<br>
&gt;<br>
&gt; &nbsp; &nbsp;resourceName == $resourceName))<br>
&gt;<br>
&gt; &nbsp; &nbsp; not (DataSource(name == $resourceName,<br>
&gt;<br>
&gt; &nbsp; &nbsp;state == ResourceState.SHUNNED ||<br>
&gt;<br>
&gt; &nbsp; &nbsp;state == ResourceState.FAILED))<br>
&gt;<br>
&gt; &nbsp; then<br>
&gt; &nbsp; &nbsp; Object[] params = {$resourceName};<br>
&gt; &nbsp; &nbsp; if (policyMgr.getMode() !=<br>
&gt; ClusterPolicyManagerMode.MAINTENANCE)<br>
&gt; &nbsp; &nbsp; {<br>
&gt;<br>
&gt; lastNotification.setResourceState(ResourceState.UNKNOWN);<br>
&gt; &nbsp; &nbsp; &nbsp; ManagerFailedAlarm alarm =<br>
&gt;<br>
&gt; &nbsp; &nbsp; &nbsp; &nbsp; new<br>
&gt; ManagerFailedAlarm(lastNotification, &quot;rule detected monitor<br>
&gt; stop&quot;,<br>
&gt;<br>
&gt;<br>
&gt; &nbsp; &nbsp;6, AlarmSeverity.FAULT);<br>
&gt; &nbsp; &nbsp; &nbsp; <a href="http://logger.info" target="_blank">logger.info</a>(alarm.toString());<br>
&gt; &nbsp; &nbsp; &nbsp; insert(alarm);<br>
&gt; &nbsp; &nbsp; &nbsp; update(lastNotification);<br>
&gt; &nbsp; &nbsp; &nbsp;}<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-dev mailing list<br>
&gt; <a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-dev"
target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
&gt;<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-dev mailing list<br>
<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><o:p></o:p></p>

</div>

</div>

</div>

<p class=MsoNormal><br>
<br clear=all>
<br>
-- <br>
&nbsp;Edson Tirelli<br>
&nbsp;JBoss Drools Core Development<br>
&nbsp;JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><o:p></o:p></p>

</div>

</body>

</html>