cancel
Showing results for 
Search instead for 
Did you mean: 

Exception when deleting a process with long running task

awelsh
Champ in-the-making
Champ in-the-making
I am doing some tests to understand the behaviour of RuntimeService.deleteProcessInstance.

I create a process with a task which loops a set number of times logging messages to the console then sleeping for 1 second.

In my test method, I call RuntimeService.startProcessInstanceByKey(), sleep for a few seconds to allow the logging activity to do a few rounds, then call RuntimeService.deleteProcessInstance().
In between the start event and the logging task I added an intermediate timer event so the startProcessInstanceByKey() call would return to the test method. I don't think this is affecting the behaviour but am mentioning it just in case.

The test method then sleeps for a number of seconds, during which time the logging activity continues to output to the console (this is after the process instance has been deleted). When the logging activity completes, the exception at the bottom of this post is thrown.

My questions are:
Is this expected behaviour when deleting a process instance? That if there is an activity in progress, it won't be interrupted and the delete doesn't wait for it to complete, and should this exception be expected in this circumstance?

Would it be possible to have a cleaner method of cancelling a process instance, where we can tell the engine to let any current activity complete and then do the deletion gracefully? or even to have the option to tell the engine to interrupt any running activity.

———————————————————————————————————————

04-Apr-2011 14:58:24 org.activiti.engine.impl.interceptor.CommandContext close
SEVERE: Error while closing command context
org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_EXE_PROCINST: PUBLIC.ACT_RU_EXECUTION FOREIGN KEY(PROC_INST_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_)"; SQL statement:
insert into ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, PARENT_ID_, SUPER_EXEC_)
    values (
      ?,
      1,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?
    ) [23002-132]
### The error may involve org.activiti.persistence.insertExecution-Inline
### The error occurred while setting parameters
### Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_EXE_PROCINST: PUBLIC.ACT_RU_EXECUTION FOREIGN KEY(PROC_INST_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_)"; SQL statement:
insert into ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, PARENT_ID_, SUPER_EXEC_)
    values (
      ?,
      1,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?
    ) [23002-132]
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:100)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:87)
   at org.activiti.engine.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:392)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:319)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:134)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:90)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:36)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
   at java.lang.Thread.run(Thread.java:619)
Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_EXE_PROCINST: PUBLIC.ACT_RU_EXECUTION FOREIGN KEY(PROC_INST_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_)"; SQL statement:
insert into ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, PARENT_ID_, SUPER_EXEC_)
    values (
      ?,
      1,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?
    ) [23002-132]
   at org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
   at org.h2.message.DbException.get(DbException.java:167)
   at org.h2.message.DbException.get(DbException.java:144)
   at org.h2.constraint.ConstraintReferential.checkRowOwnTable(ConstraintReferential.java:325)
   at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:267)
   at org.h2.table.Table.fireConstraints(Table.java:766)
   at org.h2.table.Table.fireAfterRow(Table.java:783)
   at org.h2.command.dml.Insert.insertRows(Insert.java:122)
   at org.h2.command.dml.Insert.update(Insert.java:82)
   at org.h2.command.CommandContainer.update(CommandContainer.java:70)
   at org.h2.command.Command.executeUpdate(Command.java:198)
   at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:179)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:22)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:51)
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:29)
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:72)
   at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:43)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:98)
   … 14 more
Exception in thread "pool-1-thread-1" org.apache.ibatis.exceptions.PersistenceException:
### Error updating database.  Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_EXE_PROCINST: PUBLIC.ACT_RU_EXECUTION FOREIGN KEY(PROC_INST_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_)"; SQL statement:
insert into ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, PARENT_ID_, SUPER_EXEC_)
    values (
      ?,
      1,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?
    ) [23002-132]
### The error may involve org.activiti.persistence.insertExecution-Inline
### The error occurred while setting parameters
### Cause: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_EXE_PROCINST: PUBLIC.ACT_RU_EXECUTION FOREIGN KEY(PROC_INST_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_)"; SQL statement:
insert into ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, PARENT_ID_, SUPER_EXEC_)
    values (
      ?,
      1,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?
    ) [23002-132]
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:100)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:87)
   at org.activiti.engine.impl.db.DbSqlSession.flushInserts(DbSqlSession.java:392)
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:319)
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:134)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:90)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42)
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:36)
   at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
   at java.lang.Thread.run(Thread.java:619)
Caused by: org.h2.jdbc.JdbcSQLException: Referential integrity constraint violation: "ACT_FK_EXE_PROCINST: PUBLIC.ACT_RU_EXECUTION FOREIGN KEY(PROC_INST_ID_) REFERENCES PUBLIC.ACT_RU_EXECUTION(ID_)"; SQL statement:
insert into ACT_RU_EXECUTION (ID_, REV_, PROC_INST_ID_, BUSINESS_KEY_, PROC_DEF_ID_, ACT_ID_, IS_ACTIVE_, IS_CONCURRENT_, IS_SCOPE_, PARENT_ID_, SUPER_EXEC_)
    values (
      ?,
      1,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?,
      ?
    ) [23002-132]
   at org.h2.message.DbException.getJdbcSQLException(DbException.java:316)
   at org.h2.message.DbException.get(DbException.java:167)
   at org.h2.message.DbException.get(DbException.java:144)
   at org.h2.constraint.ConstraintReferential.checkRowOwnTable(ConstraintReferential.java:325)
   at org.h2.constraint.ConstraintReferential.checkRow(ConstraintReferential.java:267)
   at org.h2.table.Table.fireConstraints(Table.java:766)
   at org.h2.table.Table.fireAfterRow(Table.java:783)
   at org.h2.command.dml.Insert.insertRows(Insert.java:122)
   at org.h2.command.dml.Insert.update(Insert.java:82)
   at org.h2.command.CommandContainer.update(CommandContainer.java:70)
   at org.h2.command.Command.executeUpdate(Command.java:198)
   at org.h2.jdbc.JdbcPreparedStatement.execute(JdbcPreparedStatement.java:179)
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:22)
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:51)
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:29)
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:72)
   at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:43)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:98)
   … 14 more
6 REPLIES 6

jbarrez
Star Contributor
Star Contributor
Are you deleting using the process instance id?

Afaik, the delete should cascade to all its child executions.

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
I have this same errors and some different but related ones AND it is reproducable. To me it happens when the engine is ending a process and begins with deleting things from the RU tables. If the variables are removed, but the execution is not (yet) and something else writes a variable to the db again, the step of removing the execution fails. This results in the same error as above.

But it could also be that the variables are removed and a not yet removed execution is signalled, goes to a transition with a condition and then you get the error that there is an unknown property
SEVERE: Error while closing command context
org.activiti.engine.ActivitiException: Unknown property used in expression
at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:55)
at org.activiti.engine.impl.el.UelExpressionCondition.evaluate(UelExpressionCondition.java:37)
at org.activiti.engine.impl.bpmn.behavior.ExclusiveGatewayActivityBehavior.leave(ExclusiveGatewayActivityBehavior.java:64)
… (nothing interesting below, believe me…)

And playing with some delays in my unit test, I can even get NPE's (note that I DO use the runtimeService!)

SEVERE: Error while closing command context
java.lang.NullPointerException
at org.activiti.engine.impl.history.handler.ActivityInstanceEndHandler.findActivityInstance(ActivityInstanceEndHandler.java:50)
at org.activiti.engine.impl.history.handler.ActivityInstanceEndHandler.findActivityInstance(ActivityInstanceEndHandler.java:77)
at org.activiti.engine.impl.history.handler.ActivityInstanceEndHandler.notify(ActivityInstanceEndHandler.java:36)
at org.activiti.engine.impl.pvm.runtime.AbstractEventAtomicOperation.execute(AbstractEventAtomicOperation.java:38)
at org.activiti.engine.impl.interceptor.CommandContext.performOperation(CommandContext.java:76)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.performOperation(ExecutionEntity.java:483)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.take(ExecutionEntity.java:326)
at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performOutgoingBehavior(BpmnActivityBehavior.java:92)
at org.activiti.engine.impl.bpmn.behavior.BpmnActivityBehavior.performDefaultOutgoingBehavior(BpmnActivityBehavior.java:49)
at org.activiti.engine.impl.bpmn.behavior.FlowNodeActivityBehavior.leave(FlowNodeActivityBehavior.java:44)
at org.activiti.engine.impl.bpmn.behavior.AbstractBpmnActivityBehavior.leave(AbstractBpmnActivityBehavior.java:37)
at org.activiti.engine.impl.bpmn.behavior.ReceiveTaskActivityBehavior.signal(ReceiveTaskActivityBehavior.java:35)
at org.activiti.engine.impl.persistence.entity.ExecutionEntity.signal(ExecutionEntity.java:309)
at org.activiti.engine.impl.cmd.SignalCmd.execute(SignalCmd.java:53)
at org.activiti.engine.impl.interceptor.CommandExecutorImpl.execute(CommandExecutorImpl.java:24)
at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:42)
at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
at org.activiti.engine.impl.RuntimeServiceImpl.signal(RuntimeServiceImpl.java:131)

I'll attach a zip file shortly

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
The attached project can be used to create the problems described above. Putting thread.sleep(…) before the set variable in within the loop and/or before the signal can be used to create different errors. Since it is timing related, I cannot tell which values are needed for your system

ronald_van_kuij
Champ on-the-rise
Champ on-the-rise
http://jira.codehaus.org/browse/ACT-813 seems related but with the diference that that is in the SAME context. The above issue is in different contexts, so it might be that a more complex solution is needed. Maybe something like setting the process to 'ended', make sure all inserts to this instance are prevented once the process is marked as ended and only after that start removing things. Marking it is something that needs to be cache aware or whatever. Does not sound like a simple solution…

cls
Champ in-the-making
Champ in-the-making

hitting the same problem...the deleteProcessInstance call is actually not terminating anything.  Our flow is still continued, and then got the exeception somehow..

cls
Champ in-the-making
Champ in-the-making

To add on top of it, after calling deleteProcessInstance, execution.isEnded() always return false, even after the exception above is thrown