cancel
Showing results for 
Search instead for 
Did you mean: 

Potential Asynch Multi Instance Call Activity Bug

rallen1
Confirmed Champ
Confirmed Champ
Hello,

I have noticed a potential bug or misunderstanding when spawning workflows. When an embedded subprocess spawns multiple workflows via call activity, and an initial task in the child workflow is set to Asynchronous, Activiti seems fail all children after the first one.

I created a unit test demonstrating it.

MyUnitTest.java:


package org.activiti;

import static org.junit.Assert.assertNotNull;

import org.activiti.engine.HistoryService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.test.ActivitiRule;
import org.activiti.engine.test.Deployment;
import org.junit.Rule;
import org.junit.Test;

public class MyUnitTest {
   
   @Rule
   public ActivitiRule activitiRule = new ActivitiRule();
   
   @Test
   @Deployment(resources = {"org/activiti/test/parent.bpmn", "org/activiti/test/child.bpmn"})
   public void test_subprocess() throws Exception {
      ProcessInstance processInstance = activitiRule.getRuntimeService().startProcessInstanceByKey("parent");
      Thread.sleep(5000);

      HistoryService historyService = activitiRule.getHistoryService();
      HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
      System.out.println("process instance end time: " + historicProcessInstance.getEndTime());
      
      assertNotNull(historicProcessInstance.getEndTime());
      assertNotNull(processInstance);
   }

}


parent.bpmn:


<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <message id="parentStart" name="parentStart"></message>
  <process id="parent" name="Parent Process" isExecutable="true">
    <startEvent id="messagestartevent1" name="Parent Start">
      <messageEventDefinition messageRef="parentStart"></messageEventDefinition>
    </startEvent>
    <subProcess id="subprocess1" name="Sub Process">
      <multiInstanceLoopCharacteristics isSequential="false">
        <loopCardinality>2</loopCardinality>
      </multiInstanceLoopCharacteristics>
      <callActivity id="callactivity1" name="child" calledElement="child"></callActivity>
      <endEvent id="endevent2" name="End"></endEvent>
      <sequenceFlow id="flow4" sourceRef="callactivity1" targetRef="endevent2"></sequenceFlow>
      <startEvent id="startevent1" name="Start"></startEvent>
      <sequenceFlow id="flow5" sourceRef="startevent1" targetRef="callactivity1"></sequenceFlow>
    </subProcess>
    <endEvent id="endevent1" name="End"></endEvent>
    <sequenceFlow id="flow3" sourceRef="subprocess1" targetRef="endevent1"></sequenceFlow>
    <scriptTask id="scripttask1" name="Script Task" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>println "parent"</script>
    </scriptTask>
    <sequenceFlow id="flow6" sourceRef="messagestartevent1" targetRef="scripttask1"></sequenceFlow>
    <sequenceFlow id="flow7" sourceRef="scripttask1" targetRef="subprocess1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_parent">
    <bpmndi:BPMNPlane bpmnElement="parent" id="BPMNPlane_parent">
      <bpmndi:BPMNShape bpmnElement="messagestartevent1" id="BPMNShape_messagestartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="80.0" y="360.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="subprocess1" id="BPMNShape_subprocess1">
        <omgdc:Bounds height="206.0" width="311.0" x="350.0" y="275.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="callactivity1" id="BPMNShape_callactivity1">
        <omgdc:Bounds height="55.0" width="105.0" x="450.0" y="353.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent2" id="BPMNShape_endevent2">
        <omgdc:Bounds height="35.0" width="35.0" x="600.0" y="363.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="startevent1" id="BPMNShape_startevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="370.0" y="363.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="730.0" y="360.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1">
        <omgdc:Bounds height="55.0" width="105.0" x="180.0" y="350.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
        <omgdi:waypoint x="555.0" y="380.0"></omgdi:waypoint>
        <omgdi:waypoint x="600.0" y="380.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
        <omgdi:waypoint x="405.0" y="380.0"></omgdi:waypoint>
        <omgdi:waypoint x="450.0" y="380.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
        <omgdi:waypoint x="661.0" y="378.0"></omgdi:waypoint>
        <omgdi:waypoint x="730.0" y="377.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
        <omgdi:waypoint x="115.0" y="377.0"></omgdi:waypoint>
        <omgdi:waypoint x="180.0" y="377.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
        <omgdi:waypoint x="285.0" y="377.0"></omgdi:waypoint>
        <omgdi:waypoint x="350.0" y="378.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


child.bpmn

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <message id="childStart" name="childStart"></message>
  <process id="child" name="Child Process" isExecutable="true">
    <startEvent id="messagestartevent1" name="Child Start">
      <messageEventDefinition messageRef="childStart"></messageEventDefinition>
    </startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <scriptTask id="scripttask1" name="Script Task" activiti:async="true" scriptFormat="groovy" activiti:autoStoreVariables="false">
      <script>println "child"</script>
    </scriptTask>
    <sequenceFlow id="flow1" sourceRef="messagestartevent1" targetRef="scripttask1"></sequenceFlow>
    <sequenceFlow id="flow2" sourceRef="scripttask1" targetRef="endevent1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_child">
    <bpmndi:BPMNPlane bpmnElement="child" id="BPMNPlane_child">
      <bpmndi:BPMNShape bpmnElement="messagestartevent1" id="BPMNShape_messagestartevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="90.0" y="353.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
        <omgdc:Bounds height="35.0" width="35.0" x="330.0" y="353.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNShape bpmnElement="scripttask1" id="BPMNShape_scripttask1">
        <omgdc:Bounds height="55.0" width="105.0" x="176.0" y="343.0"></omgdc:Bounds>
      </bpmndi:BPMNShape>
      <bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
        <omgdi:waypoint x="125.0" y="370.0"></omgdi:waypoint>
        <omgdi:waypoint x="176.0" y="370.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
      <bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
        <omgdi:waypoint x="281.0" y="370.0"></omgdi:waypoint>
        <omgdi:waypoint x="330.0" y="370.0"></omgdi:waypoint>
      </bpmndi:BPMNEdge>
    </bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>


Any help is greatly appreciated. Thanks.
5 REPLIES 5

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Rallen,

I have fixed your jUnit test. Here you can find project which is passing your test
https://github.com/martin-grofcik/activiti-unit-test-template/tree/rallen

Regards
Martin

rallen1
Confirmed Champ
Confirmed Champ
Hey Martin,

Thanks for the quick reply. I actually forgot to include my activiti-cfg file. My mistake may have actually demonstrated what might be the cause though, as my config file is using the AsyncExecutor over the JobExecutor, as recommended in the Activiti User Guide. My pom is also using Activiti Engine 5.17.0.

<code>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd">

  <bean id="processEngineConfiguration"
  class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">>
    <property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_ON_EXIT=FALSE" />
    <property name="jdbcDriver" value="org.h2.Driver" />
    <property name="jdbcUsername" value="sa" />
    <property name="jdbcPassword" value="" />
    <property value="full" name="history" />
    <property name="asyncExecutorEnabled" value="true"/>
    <property name="asyncExecutorActivate" value="true"/>
  </bean>
</beans>
</code>

Thanks for the help.

rallen1
Confirmed Champ
Confirmed Champ
Hello Martin,

I was wondering if there has been any update?

I have also been having some issues when putting activiti under a heavy load involving subprocesses. I am also observing different behaviour when using the async or job executor. The heavy load problem may require its own thread though depending on your thoughts here.

As always, thank you for any help.

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Rallen,

Async executor behaves differently. I think that's a bug. The only question is how should it behave.
(@Tijs & @Joram have a look, please)

Regards
Martin

martin_grofcik
Confirmed Champ
Confirmed Champ
It seems that there is an issue with MultiInstance loop.

Regards
Martin