Errors while trying to delete a process instance from the Java API

Hi all,

I’m trying to delete a process instance via the Java API at the end of a task based on a variable;
runtimeService.deleteProcessInstance(String processInstanceId, String deleteReason);

When this code is in a ‘complete’ task listener, I get following exception:

2016-08-09 13:16:23,421 WARNING [ExceptionHandler] (default task-17) org.camunda.bpm.engine.rest.exception.RestException: Cannot submit task form a29ce949-5e22-11e6-9e2b-4e8dcd585ba0: cannot signal execution 87f889fb-5e22-11e6-9e2b-4e8dcd585ba0: it has no current activity

When called in an ‘end’ execution listener, the submit-form call hangs and after a while following exception occurs:

2016-08-09 13:31:16,768 ERROR [org.jboss.as.ejb3.invocation] (default task-6) WFLYEJB0034: EJB Invocation failed on component ApproveNotification for method public abstract void org.camunda.bpm.engine.delegate.ExecutionListener.notify(org.camunda.bpm.engine.delegate.DelegateExecution) throws java.lang.Exception: javax.ejb.EJBTransactionRolledbackException: WFLYEJB0378: Failed to acquire a permit within 5 MINUTES
2016-08-09 13:31:29,646 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012108: CheckedAction::check - atomic action 0:ffffc0a80c1e:78ef5394:57a99fd5:2a4b aborting with 1 threads active!
2016-08-09 13:31:29,657 WARN [com.arjuna.ats.arjuna] (Transaction Reaper Worker 0) ARJUNA012121: TransactionReaper::doCancellations worker Thread[Transaction Reaper Worker 0,5,main] successfully canceled TX 0:ffffc0a80c1e:78ef5394:57a99fd5:2a4b

I have no idea how to solve the exception. My intent is to stop a process instance (based on user form unput) while keeping the history in the tables + having the delete_reason filled in.

Hi Nico Van Belle,

I think you could use “Terminate Event”
https://docs.camunda.org/manual/7.5/reference/bpmn20/events/terminate-event/

Where you could terminate the whole process instance based on user input “process variable value”
& you could use a custom process variable to store the delete reason

Hi Hassan,

Thank you for the reply!

The reason for really canceling the process instead of terminating it is because reporting is a big deal in the project. Fetching the process instances in the history table and reading the delete_reason_ there would be an asset.

When the solution I’m having in mind is impossible then sure, I’ll use a workaround.

Kind regards,
Nico

Hi Nico,

Modifying a process instance (e.g. cancellation, process instance modification, migration, etc.) from within itself is problematic in the process engine and we do not test such cases extensively.

I’d suggest you use either Hassan’s workaround or instead of submitting the user task form, directly submit a cancel HTTP request.

Cheers,
Thorben

Hi Thorben,

Ok, thank you for the reply. I will use the workaround then suggested by @hassang.