Unable to recover form multiple executions being created

In a process definition we were using a delegate class as an execution listener on a service task that called a different delegate class. This seems to fork the execution in the process instance and cause two different executions to continue on through the process instance. This created a race condition where sometimes the different executions would try to update the DB and fail due to a foreign key constraint missing. (This seems to happen while exiting a call activity later in the workflow.)

We have removed the listener and set it up to run as its own service task, which has cleared up the problem, but I have a couple of questions:

  • Why is this allowed to happen? It seems like some safeguard should have prevented this state.
  • When this happens, is there any way to clean up the the process instance?
    • The process definition has a cancel handler, so I triggered a cancel signal, but then that had a call activity and dead locked on the DB updates again.
    • I tried to delete the workflow using the runtime service deleteProcessInstance function but that throws a TooManyResultsException when it gets multiple executions back for the process instance.

I looked for a way to kill one of the executions, but could not find one.

Depends - in the delegate I’m assuming you implemented ActivityBehavior or used casts?

Is it possible the share (some) code of the delegate that does the forking? It’s hard to reason about what could be happening here.

That’s not a default thing in Flowable - so I’m assuming this is custom?

And you passed the process instance id? That’s a very weird exception … Flowable won’t do this in any of the default logic. It looks like that delegate is doing some low-level stuff … it would help if you can share a bit more details about it here.