Execution hangs/stops executing on inclusiveGateway inside event subprocess

Hi all,

We stumbled onto a problem when using the event sub process in combination with an inclusive gateway. This seems to block the execution of the process completely. When analyzing the process, we found that there is an execution that hangs/blocks on the activity of the inclusive gateway (in the scope of the event sub process).

Screenshot from 2017-09-26 09-36-53

An investigation of the execution tree yields following results:

execution tree before the event
Screenshot from 2017-09-26 09-46-27
execution tree after the event has been fired
Screenshot from 2017-09-26 09-46-53

I tried (and succeeded) to replicate this behaviour by writing a test case for this.

package org.flowable.engine.test.bpmn.subprocess;

import org.flowable.engine.*;
import org.flowable.engine.common.AbstractEngineConfiguration;
import org.flowable.engine.common.impl.interceptor.Command;
import org.flowable.engine.common.impl.interceptor.CommandContext;
import org.flowable.engine.impl.EventSubscriptionQueryImpl;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.EventSubscription;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.idm.api.Group;
import org.flowable.idm.api.User;
import org.flowable.task.service.Task;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayInputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class InclusiveGateInsideEventSubProcessTest {


    private String bpmnXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<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:flowable=\"http://flowable.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/processdef\">\n" +
            "\n" +
            "    <message id=\"test\" name=\"test\"></message>\n" +
            "    <process id=\"b92d819d-481f-4001-834e-cbdfa6ee0fad\" name=\"ESUBP\" isExecutable=\"true\">\n" +
            "        <startEvent id=\"sid-BB429B30-D1B2-42EC-961C-757EF2CDED60\"></startEvent>\n" +
            "        <userTask id=\"sid-902CFFB5-41A3-42C0-8FDB-01989321FC28\" name=\"My initial task\" flowable:candidateGroups=\"admin\"></userTask>\n" +
            "        <sequenceFlow id=\"sid-2B6DD690-BBCB-4171-8036-5F5DE0EF5203\" sourceRef=\"sid-BB429B30-D1B2-42EC-961C-757EF2CDED60\" targetRef=\"sid-902CFFB5-41A3-42C0-8FDB-01989321FC28\"></sequenceFlow>\n" +
            "        <endEvent id=\"sid-74359125-08BE-431B-80CD-3BF4E5319A12\"></endEvent>\n" +
            "        <sequenceFlow id=\"sid-5B582BE8-68AE-4D6E-BA3E-A677E32BC66B\" sourceRef=\"sid-902CFFB5-41A3-42C0-8FDB-01989321FC28\" targetRef=\"sid-74359125-08BE-431B-80CD-3BF4E5319A12\"></sequenceFlow>\n" +
            "        <subProcess id=\"sid-DD31A8B5-70AE-449B-8695-34A05C534B2B\" name=\"subProcess\" triggeredByEvent=\"true\">\n" +
            "            <startEvent id=\"sid-1C121AA8-87A7-4C31-ACD8-C06E3E9C2EAD\" isInterrupting=\"false\">\n" +
            "                <messageEventDefinition messageRef=\"test\"></messageEventDefinition>\n" +
            "            </startEvent>\n" +
            "            <inclusiveGateway id=\"sid-063D15E8-403B-447F-8D72-E605F86E464A\"></inclusiveGateway>\n" +
            "            <endEvent id=\"sid-492C047C-E4D7-4AEF-9BFB-E021060EB41B\"></endEvent>\n" +
            "            <inclusiveGateway id=\"sid-A42DF850-8D0A-4270-BE47-85A706BAC71D\"></inclusiveGateway>\n" +
            "            <userTask id=\"sid-731EFDCD-442B-4150-B180-5428D7302FC3\" name=\"test\" flowable:candidateGroups=\"admin\"></userTask>\n" +
            "            <userTask id=\"sid-E8BE4027-1EAE-4ABF-8A66-F007B72AB3DB\" name=\"test2\" flowable:assignee=\"admin\" flowable:candidateGroups=\"admin\" />\n" +
            "            <sequenceFlow id=\"sid-EACFC7D1-2F28-4ABA-861D-FA884C2C2DB9\" sourceRef=\"sid-1C121AA8-87A7-4C31-ACD8-C06E3E9C2EAD\" targetRef=\"sid-063D15E8-403B-447F-8D72-E605F86E464A\"></sequenceFlow>\n" +
            "            <sequenceFlow id=\"sid-8F280C95-1770-4734-933A-5B9C3BFBDA3F\" sourceRef=\"sid-731EFDCD-442B-4150-B180-5428D7302FC3\" targetRef=\"sid-A42DF850-8D0A-4270-BE47-85A706BAC71D\"></sequenceFlow>\n" +
            "            <sequenceFlow id=\"sid-BE6C05DF-219C-43CF-BEE3-62339EAD1F86\" sourceRef=\"sid-E8BE4027-1EAE-4ABF-8A66-F007B72AB3DB\" targetRef=\"sid-A42DF850-8D0A-4270-BE47-85A706BAC71D\"></sequenceFlow>\n" +
            "            <sequenceFlow id=\"sid-9129C3C3-E0E9-4D1B-946B-64BE196CCE19\" sourceRef=\"sid-A42DF850-8D0A-4270-BE47-85A706BAC71D\" targetRef=\"sid-492C047C-E4D7-4AEF-9BFB-E021060EB41B\"></sequenceFlow>\n" +
            "            <sequenceFlow id=\"sid-977D5F51-5BE8-41F2-9123-F0E2E25BE7E2\" sourceRef=\"sid-063D15E8-403B-447F-8D72-E605F86E464A\" targetRef=\"sid-731EFDCD-442B-4150-B180-5428D7302FC3\">\n" +
            "                <conditionExpression xsi:type=\"tFormalExpression\"><![CDATA[${test2}]]></conditionExpression>\n" +
            "            </sequenceFlow>\n" +
            "            <sequenceFlow id=\"sid-620428D7-8894-4569-8E18-C89123B0DDB6\" sourceRef=\"sid-063D15E8-403B-447F-8D72-E605F86E464A\" targetRef=\"sid-E8BE4027-1EAE-4ABF-8A66-F007B72AB3DB\">\n" +
            "                <conditionExpression xsi:type=\"tFormalExpression\"><![CDATA[${test}]]></conditionExpression>\n" +
            "            </sequenceFlow>\n" +
            "        </subProcess>\n" +
            "    </process>\n" +
            "</definitions>";

    private ProcessEngine processEngine;

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Before
    public void setUp() throws Exception {
        ProcessEngineConfiguration configuration = ProcessEngineConfiguration
                .createStandaloneInMemProcessEngineConfiguration()
                .setDatabaseSchemaUpdate(AbstractEngineConfiguration.DB_SCHEMA_UPDATE_DROP_CREATE);
        this.processEngine = configuration.buildProcessEngine();

        IdentityService identityService = configuration.getIdentityService();
        Group g = identityService.newGroup("admin");
        identityService.saveGroup(g);
        User u = identityService.newUser("admin");
        identityService.saveUser(u);
        identityService.createMembership("admin", "admin");

    }

    @After
    public void teardown() {
        processEngine.close();
    }


    @Test
    public void testThatProcessGetsTwoTasksAfterInclusiveGateway() throws Exception {

        Deployment deployment = this.processEngine
                .getRepositoryService()
                .createDeployment()
                .disableSchemaValidation()
                .addInputStream("inclusiveGateInsideEventSubProcess.bpmn20.xml", new ByteArrayInputStream(bpmnXml.getBytes(StandardCharsets.UTF_8)))
                .deploy();
        RuntimeService runtimeService = this.processEngine.getRuntimeService();
        TaskService taskService = this.processEngine.getTaskService();
        RepositoryService repositoryService = this.processEngine.getRepositoryService();

        ProcessDefinition processDefinition = repositoryService
                .createProcessDefinitionQuery()
                .deploymentId(deployment.getId())
                .singleResult();

        final ProcessInstance instance = runtimeService.createProcessInstanceBuilder()
                .processDefinitionId(processDefinition.getId())
                .variable("test", true)
                .variable("test2", true)
                .start();

        List<Task> tasks = taskService.createTaskQuery()
                .processDefinitionId(instance.getProcessDefinitionId())
                .taskCandidateGroup("admin")
                .list();

        assertEquals(1, tasks.size());


        String executionId = processEngine.getManagementService().executeCommand(new Command<String>() {
            @Override
            public String execute(CommandContext commandContext) {
                EventSubscriptionQueryImpl q = new EventSubscriptionQueryImpl(commandContext);
                q.processInstanceId(instance.getProcessInstanceId());

                List<EventSubscription> subs = CommandContextUtil
                        .getEventSubscriptionEntityManager()
                        .findEventSubscriptionsByQueryCriteria(q);

                assertEquals(1, subs.size());
                EventSubscription sub = subs.get(0);
                assertEquals(sub.getEventName(), "test");

                return sub.getExecutionId();
            }
        });

        runtimeService.messageEventReceived("test", executionId);


        tasks = taskService.createTaskQuery()
                .processDefinitionId(instance.getProcessDefinitionId())
                .list();

        assertEquals(3, tasks.size());


    }
}

Note: try replacing the inclusiveGateway in this test with parallelGateway and you will see that this works perfectly. Some other things we’ve tried are:

  • Set the event sub process to interrupting
  • Put a user task in between the start message event and the inclusive gateway

Please let me know if you need further information about this, I’m happy to help!

That is a real bug indeed. Thanks for the excellent test, that helps a lot. I think it’s due to a bug in the algorithm for determining if an inclusive gw can be reached. Probably it needs more attention wrt event subprocesses.

Can you

  1. create a github issue
  2. create a PR containing your test (you did the hard work, so you should get the credit :wink: ).

Thanks!

Hi,

I already created the issue referencing to the forum, and now I attached the PR: see https://github.com/flowable/flowable-engine/issues/582.

Superb, many thanks!

@mlippens : merged your test case + added fix. Thanks for the excellent bug report!

Nice, glad I could help.