Non terminating end event in gateway removes event subscriptions

Hi,

I found a possible issue with respect to an end event that removes (message) event subscriptions prematurely. In the following process, upon reaching the end of either task 2 or task 3, an end event is reached. One can still proceed with the process as would be expected, but the side effect is that the existing message subscription has now been removed.

Further analysis yields that the end event cleans up the execution by planning the EndExecutionOperation on the agenda. Consequently, it will call ExecutionEntityManager.deleteExecutionAndRelatedData, which will then clean up the message subscription of the message start event.

Granted, normally you’d join the parallel gateway again after both tasks. But I used this scenario to simplify the test case attached to it. As such, the end event of task 2 or task 3 should not cause the message subscription to be removed.

Screenshot from 2017-09-29 15-43-52

@Deployment
public void testNonTerminatingEndEventShouldNotRemoveSubscriptions() {
    ProcessDefinition processDefinition = repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionKey("ec7ca606-a4f2-11e7-abc4-cec278b6b50a")
            .singleResult();

    final ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
            .processDefinitionId(processDefinition.getId())
            .start();

    List<Task> tasks = taskService.createTaskQuery()
            .processInstanceId(processInstance.getProcessInstanceId())
            .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(processInstance.getProcessInstanceId());

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

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

            return sub.getExecutionId();
        }
    });
    taskService.complete(tasks.get(0).getId());

    tasks = taskService.createTaskQuery()
            .processInstanceId(processInstance.getProcessInstanceId())
            .taskName("task 2")
            .list();
    assertEquals(1, tasks.size());

    taskService.complete(tasks.get(0).getId());

    tasks = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).list();
    assertEquals(1, tasks.size());

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

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

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

            return sub.getExecutionId();
        }
    });

}

Also see https://github.com/flowable/flowable-engine/issues/587 & referenced pull request for the test case.


Note: I state the bug here to be present by working with a parallel gateway, but it can be reproduced also with other gateways (such as an inclusive gateway)


bpmn process (xml)
https://gist.github.com/mlippens/4d8ff4f8cb017f68ab7db3e11d53b51c

That’s indeed a bug, thanks a lot for reporting with (again) an excellent test! Will look into it and continue discussion in the issue.

1 Like