How to delete a process?


back then in Activiti and up to Flowable 6.2 the following code worked as (at least I) expected:

    RuntimeService runtimeService = processEngine.getRuntimeService();
    String pId = runtimeService.startProcessInstanceById (processDefinition.getId ()).getId ();
    System.out.println ("Process " + pId + " started");
    // give process somw time to "do" something
    Thread.sleep (3000);
    System.out.println ("Deleting process " + pId);
    runtimeService.deleteProcessInstance (pId, null);
    System.out.println ("Process deleted");

Process 5 started
Deleting process 5
Process deleted

The Flowable version currently in use (6.7.2), however, gives me an exception:

Concurrent update in table “ACT_RU_EXECUTION”: another transaction has updated or deleted the same row [90131-212]

While I understand what happens, I’m somewhat puzzled.

Is this behavior change intended? If so, what is the recommended way to delete a running process instance?

Thanks, stm.

On what line does this exception happen?

This only makes sense if you have async tasks. Can you share more details about your model?

The exception is thrown at runtimeService.deleteProcessInstance (pId, null);.

Yes, tasks are asynchronous. The model is a trivial example to showcase this behaviour. One ServiceTask between Start and End events. The task is a Java class simply doing a sleep ().

I can share the full set of files. What’s the preferred way to do this here?

Same problem with test case reported in this existing GitHub issue (considering that if we are not able to stop a running workflow it can be considered as a bug, no? ;))

Best Regards

The suspend fails because Flowable uses optimistic locking (and only one database transaction can win). This is why it only works when in a wait state. And even then, which transaction will win is random (determined by the database). An instance can only be deleted/suspended when it’s not executing anything else at that moment. The only alternative I see is an async job that would retry on failure and eventually will succeed.

The mechanism in itself is understood. The question is: Is there a way to successfully terminate a running process. Looks like this is not the case. I guess it’s somewhat hard as there is no safe way to stop the async executor’s threads.

Looks like we are left with implementing some cancel functionality in the process itself or wait until it terminates peacefully.

Correct. Note that if the JVM is doing pure CPU work (no IO), there isn’t even a way to stop a thread programmatically.