cancel
Showing results for 
Search instead for 
Did you mean: 

How to Handle Errors due to Database Timeouts

zlatan316
Champ on-the-rise
Champ on-the-rise
Hi,

I have implemented a Java class which is able to run MS Project Server Reports. These are generated via an external webservice. The method call which retrieves the report can sometimes take a while to return the report instance. Because the transaction for the Process in Activiti has been open for more than a few minutes, a database timeout occurs.

I was wondering if there was a way to capture these errors which are thrown by the Activiti Engine,

My catch block is as below which throws a BPMNError but the flow does not take the 'error route' when this particular timeout exception occurs.
<code>
       catch(Exception ex){
          SafeLogger.checkAndWriteToLog(ex.toString(), logger);
          ex.printStackTrace();
          throw new BpmnError(ex.toString());          
       }
<code>

The error stack trace is as follows
<code>
08:09:36,978 [pool-1-thread-53] ERROR org.activiti.engine.impl.pvm.runtime.AtomicOperationProcessEnd  - Error while completing sub process of execution ProcessInstance[21415]
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 207,265 milliseconds ago.  The last packet sent successfully to the server was 1 milliseconds ago.
### The error may exist in org/activiti/db/mapping/entity/IdentityLink.xml
### The error may involve org.activiti.engine.impl.persistence.entity.IdentityLinkEntity.selectIdentityLinksByProcessInstance-Inline
### The error occurred while setting parameters
### SQL: select * from ACT_RU_IDENTITYLINK where PROC_INST_ID_ = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

The last packet successfully received from the server was 207,265 milliseconds ago.  The last packet sent successfully to the server was 1 milliseconds ago.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:107)
        at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:98)
        at org.activiti.engine.impl.db.DbSqlSession.selectListWithRawParameter(DbSqlSession.java:286)
        at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:277)
        at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:272)
        at org.activiti.engine.impl.db.DbSqlSession.selectList(DbSqlSession.java:253)
………………
<code>
Is there a way to capture these in Activiti?
5 REPLIES 5

zlatan316
Champ on-the-rise
Champ on-the-rise
Apologies for the format of the post, i cannot seem to edit it.

pmsevestre
Champ in-the-making
Champ in-the-making
Hi,

In my environment I delegate such "long running" activities to a job scheduler. In the process definition I use "User Task" activities whenever I want to model a external job execution. The external job scheduler can then use the REST api or use a different Activiti engine instance (which points to the same DB,  of course) in order to acquire jobs. Once the job is complete, you use the "Task Service" API to inform Activiti that the user task is complete, and your process instance moves on.

This approach has the following advantages:

* No database transaction timeout
* Better scalability
* The external task can be assigned to a a dedicated node, leading to better resource utilization.
* Easier recovery from system errors

The downsize is the extra complexity of running a separate job scheduler, but, IMO,  I think it pays off.


zlatan316
Champ on-the-rise
Champ on-the-rise
Thanks for your response. I am planning on using the Scheduler functionality in the new 5.17 version of Activiti. But currently we have 5.14.

I actually just wanted to know that if we were to have a Service Task open for too long, can we catch the timeout error using an error event and drive the workflow to a different path?

trademak
Star Contributor
Star Contributor
No, a service task is executed until it's ready. We don't allow for timeout events.

Best regards,

zlatan316
Champ on-the-rise
Champ on-the-rise
Thanks trademak. We will have to research the use of CAML to execute these long-running tasks outside of Activiti.