[jboss-jira] [JBoss JIRA] Created: (JBRULES-2114) Drools hangs with deadlock after it has initialized a rule (in multithreaded environment)

Andrey Nechaev (JIRA) jira-events at lists.jboss.org
Fri Jun 5 08:12:07 EDT 2009


Drools hangs with deadlock after it has initialized a rule (in multithreaded environment)
-----------------------------------------------------------------------------------------

                 Key: JBRULES-2114
                 URL: https://jira.jboss.org/jira/browse/JBRULES-2114
             Project: JBoss Drools
          Issue Type: Bug
      Security Level: Public (Everyone can see)
          Components: drools-core
    Affects Versions: 4.0.6
            Reporter: Andrey Nechaev
            Assignee: Mark Proctor
            Priority: Critical


Here is a scenario when drools core hangs with a deadlock:
Suppose we heve a rule throwing an exception in the RHS. 
So, if:
1. Thread A updates the Rule Base with the rule 
2. The rule fires (current thread is Thread A)
3. Rule's RHS throws an exception (still having Thread A as current)
4. Thread B tries to update the Rule Base or the Working Memory (for example, the Thread B inserts a fact)
in such a case the Thread B falls into infinite wait() loop.
Here is the test case showing such a behavior:

package com.test;

import java.io.StringReader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;

public class DroolsTest2 {
	private final static String rule = "" + 
	"package test\n" +
	"import com.test.DroolsTest2;\n" +
	"rule test\n" +
		"\twhen\n" +
		"\tthen\n" +
			"\t\tDroolsTest2.fail();" +
	"end";
	
	private static Object sem = new Object();
	private static boolean seed = false;
	
	public static void main(String[] args) throws Exception {
		final RuleBase rb = RuleBaseFactory.newRuleBase();
		final WorkingMemory wm = rb.newStatefulSession();
		new Thread(new Runnable() {
			@Override
			public void run() {
				seed = false;
				PackageBuilder bld = new PackageBuilder();
				try {
					bld.addPackageFromDrl(new StringReader(rule));				
					rb.addPackage(bld.getPackage());
				} catch(Exception e) {					
				} finally {
					synchronized (sem) {
						seed = true;
						sem.notify();
					}
				}
			}
		}).start();
		Thread ins = new Thread(new Runnable() {
			@Override
			public void run() {
				while(!seed) {
					synchronized (sem) {
						try {
							sem.wait();
						} catch (InterruptedException e) {}
					}
				}
				wm.insert(new Object());
			}
		});
		ins.start();
		ins.join();
	}
	
	public static void fail() {
		throw new IllegalStateException("fail!");
	}
}


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list