AnsweredAssumed Answered

Transaction Deadlock

Question asked by flavio.donze on Apr 9, 2013
Latest reply on Apr 19, 2013 by flavio.donze
I get the following exception wenn I run two workflows at the same time.

com.microsoft.sqlserver.jdbc.SQLServerException: Transaction (Process ID 55) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
   at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:213) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:388) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:338) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:5574) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1734) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154) ~[sqljdbc4.jar:na]
   at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:320) ~[sqljdbc4.jar:na]
   at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[org.apache.commons.dbcp_1.4.0.jar:1.4]
   at org.apache.commons.dbcp.DelegatingPreparedStatement.execute(DelegatingPreparedStatement.java:172) ~[org.apache.commons.dbcp_1.4.0.jar:1.4]
   at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:41) ~[mybatis-3.1.1.jar:3.1.1]
   at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:66) ~[mybatis-3.1.1.jar:3.1.1]
   at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:45) ~[mybatis-3.1.1.jar:3.1.1]
   at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:108) ~[mybatis-3.1.1.jar:3.1.1]
   at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:75) ~[mybatis-3.1.1.jar:3.1.1]
   at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:145) ~[mybatis-3.1.1.jar:3.1.1]
   at org.apache.ibatis.session.defaults.DefaultSqlSession.delete(DefaultSqlSession.java:158) ~[mybatis-3.1.1.jar:3.1.1]
   at org.activiti.engine.impl.db.DbSqlSession$DeleteById.execute(DbSqlSession.java:146) ~[activiti-engine-5.10.jar:5.10]
   at org.activiti.engine.impl.db.DbSqlSession.flushDeletes(DbSqlSession.java:483) ~[activiti-engine-5.10.jar:5.10]
   at org.activiti.engine.impl.db.DbSqlSession.flush(DbSqlSession.java:371) ~[activiti-engine-5.10.jar:5.10]
   at org.activiti.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:157) ~[activiti-engine-5.10.jar:5.10]
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:109) ~[activiti-engine-5.10.jar:5.10]
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49) ~[activiti-engine-5.10.jar:5.10]
   at org.activiti.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:42) ~[activiti-spring-5.10.jar:na]
   at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130) ~[org.springframework.transaction_3.0.5.RELEASE.jar:3.0.5.RELEASE]
   at org.activiti.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:40) ~[activiti-spring-5.10.jar:na]
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33) ~[activiti-engine-5.10.jar:5.10]
   at org.activiti.engine.impl.RuntimeServiceImpl.signal(RuntimeServiceImpl.java:137) ~[activiti-engine-5.10.jar:5.10]
   at com.softmodeler.workflow.service.impl.WorkflowService.start(WorkflowService.java:221) ~[com.softmodeler.workflow/:na]
   at com.softmodeler.workflow.service.impl.WorkflowService.startWorkflow(WorkflowService.java:186) ~[com.softmodeler.workflow/:na]

I found out (http://stackoverflow.com/questions/6662504/activiti-deadlock-occurs-under-jmeter-performance-test) that I have to remove the "receiveTask" that I added.
The problem is that I added this "receiveTask" only for the reason that activiti stores its workflow into the db (http://forums.activiti.org/en/viewtopic.php?f=6&t=2375&start=0).

This is the workflow definition part:

      <sequenceFlow id="startToWait" sourceRef="start" targetRef="wait"/>
      <receiveTask id="wait" name="wait"/>
      <sequenceFlow id="waitToTranslate" sourceRef="wait" targetRef="translate"/>  

On the code side I then to this.

      try {
         identiyService.setAuthenticatedUserId(creator);
         ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables);
         processInstanceId = instance.getId();
      } catch (Throwable e) {
         throw ServerUtil.createServerException(e);
      } finally {
         identiyService.setAuthenticatedUserId(null);
      }
      
      Execution execution = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).activityId("wait") //$NON-NLS-1$
            .singleResult();
      if (execution != null) {
         identiyService.setAuthenticatedUserId(null);
         runtimeService.signal(execution.getId());
      }

This whole hack is done that I can access workflow data durring the workflow, using the following code in a workflow, the currently running process is not listed.

ProcessInstance instance = runtimeService.startProcessInstanceByKey(processKey, variables);
for (ProcessInstance in : runtimeService.createProcessInstanceQuery().list()) {
   System.out.println("RUNNING>: " + in.getId() + " " + in.getProcessDefinitionId());
}


So I was wondering is there a better solution? Workaround?
Should I report a bug?

greets and thanks for any help!
Flavio

Outcomes