cancel
Showing results for 
Search instead for 
Did you mean: 

Error on loop with asynchronous activities

mmaker1234
Champ in-the-making
Champ in-the-making
Hello Activiti developers,

I wanted to better understand what is the actual behavior of the "local" and "global" process variables and started with an example, which revealed many problems.

Please find attached a simplified example to demonstrate two of these problems: a process definition with three script (JavaScript) activities (
initVars
,
inc
, and
printVars
) and an XOR gateway.

The problem with the attached process definition is that any process instance execution fails with[java]May 13, 2013 3:00:21 PM org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: Query return 2 results instead of max 1
    at org.activiti.engine.impl.AbstractQuery.executeSingleResult(AbstractQuery.java:162)
    at org.activiti.engine.impl.AbstractQuery.execute(AbstractQuery.java:141)
    at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
    at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:61)
    …[/java]

The process definition is attached as TestLocalVariablesSimple.bpmn_.txt (of course you should rename it to TestLocalVariablesSimple.bpmn in order to review it) and a process instance execution log is attached as TestLocalVariablesSimple.log_.txt

While reading the execution log you will see
org.activiti.engine.impl.cmd.NoJobRetriesCmd
- this is my modification of the Activiti's DecrementJobRetriesCmd - I just do not want the jobs to retry. I can provide its code if you need it.

If I remove the Asynchronous flag from the activities included in the loop (
inc
and
printVars
) the process instance runs fine for small number of cycle repetitions.

The other problem is that each run fails with the following error when I increase the limit of the cycle to 100 : [java]
INFO: start Activity definitionId=inc, processId=77915, executionId=77915, name='inc', with properties: {default=null, name=inc, documentation=null, type=scriptTask}, persistent state: {isActive=true, activityId=inc, parentId=null, isScope=true, cachedEntityState=4, businessKey=null, suspensionState=1, isEventScope=false, superExecution=null, processDefinitionId=TestLocalVariablesSimple:5:77914, isConcurrent=false}, ProcessInstance id=77915, Execution id=77915, ProcessDefinition(id)='TestLocalVariablesSimple:5:77914', vegas_version: 'null', Scope
Exception in thread "pool-1-thread-4" java.lang.StackOverflowError
    ….
[/java]It seems that the execution of the consecutive activities runs in the context of the JavaScript expression, which does not seems correct.

Please find the details in the attached process definition TestLocalVariablesSimpleSynchronous .bpmn_.txt and the corresponding execution log TestLocalVariablesSimpleSynchronous.log_.txt

Please help me to sort out these two problems.

Best Regards,
Monique
18 REPLIES 18

jbarrez
Star Contributor
Star Contributor
First problem: I can't seem to reproduce it. When I run the process, I see this being printed out:

  l = 4
  global l = 4.0
  local l = 4.0

Second problem: yes, this is a known bug for the moment. A tricky one too. We're trying to fix it for a while now … hopefully the next release contains a fix.

mmaker1234
Champ in-the-making
Champ in-the-making
Hello Joram,

I'm very sorry that I forgot to mention that I tested with Activiti 5.12 (not 5.12.1) on Windows 7 environment. I will try to run the test on Linux.

mmaker1234
Champ in-the-making
Champ in-the-making
OK, I can confirm that TestLocalVariablesSimple.bpmn runs fine on Linux. It seems the guilty for the first problem (as for others reported by me) is the Windows environment.

Currently I'm trying to terminate the process instances failed during my tests and what I observe is that the termination on Windows environment fails with the same error ("Query return 2 results instead of max 1"), while on Linux it succeeds. This tends me to think that the problem is due to some racing conditions, which do not happen on Linux but I'm afraid that it is only matter of time they to happen.

jbarrez
Star Contributor
Star Contributor
A racing condition sounds really strange as we developed the job executor to cope exactly with these situations (but ofc no code is perfect).

However it might be in the area of character encodings … ie linux is case sensistive … windows is not. Just guessing here.

mmaker1234
Champ in-the-making
Champ in-the-making
Hello Joram,

I did not understood your note on the OS case sensitivity… I think that it does not affect the work of the JVM (and the Java applications correspondingly).

Please note that the process definition where the activities are synchronous (the "Asynchronous" flag is not set) is running "well" on both Windows and Linux, while the definition where the activities are asynchronous is running only on Linux. The state of the "Asynchronous" flag is the only difference in the activities properties - the activity names in both definitions are the same.

The race conditions might not be in your code - there is always a possibility the (DB) transactions to be handled differently on Windows and Linux. Actually, the error message doesn't state instances of what object were found to be surplus, so it's not easy to build guesses for the reason of the problem.

jbarrez
Star Contributor
Star Contributor
My point was: if it works on one JVM (Linux, which is also the most 'trustworthy' imo), it should work on other JVM's too. Unless there is a difference between the JVM confifguration, and character encoding is one of these areas.

Of course it can be related to different threading/concurrency models and databases. Can you create a simple junit test that always fails on windows, but works on linux?

mmaker1234
Champ in-the-making
Champ in-the-making
Hello Joram,

I've just tried to create a test case but it runs fine in Eclipse environment with the standard H2 (in memory) DB.

Could you advice me on how to set-up my command-line environment to run the test project (ascendant/modification of activiti-unit-test-template-master)? Please note that we are using Ant and I'm not familiar to Maven, although I've managed to create the build environment for Activiti sources and installed the M2Eclipse plugin on my Eclipse IDE.

jbarrez
Star Contributor
Star Contributor
I've you've followed the activiti-unit-test-template running the test is as easy as:

<code>
mvn clean test
</code>

That runs all unit tests in src/test/java

mmaker1234
Champ in-the-making
Champ in-the-making
Hello Joram,

The test is attached as <code>test.LoopWithAsynchActivities.zip</code>_.txt

It seems I found the problem and it is related to the logging listeners implemented according to this thread. Now the test fails also in Eclipse environment and with H2 (in-memory) DB (both command-line and in Eclipse) on Windows.

The following listeners are registered in the configuration:    <property name="postBpmnParseHandlers">
      <list>
        <bean class="org.activiti.engine.parse.ProcessInstanceLoggersRegistrator" />
        <bean class="org.activiti.engine.parse.ActivityInstanceLoggersRegistrator" />
        <bean class="org.activiti.engine.parse.EventDefinitionLoggersRegistrator" />
      </list>
    </property>

The listener classes are in the attached <code>parse.zip</code>_.txt. You should add them to <code><Activiti-5.12>/modules/activiti-engine/src/main/java/org/activiti/engine/parse</code> directory and rebuild the Activiti 5.12 engine. (At least this is where these classes are in my environment - yes, I preferred to put them in the Activiti distribution instead in my project).

It seems I did something wrong but what is it?