Camunda holds DB connection during service task run?


#1

Does camunda hold DB connection during service task run?
I’m asking because I’ve faced a problem that when my long running service task completes camunda fails with this exception:

org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: org.postgresql.util.PSQLException: This connection has been closed.
### The error may exist in org/camunda/bpm/engine/impl/mapping/entity/HistoricVariableInstance.xml
### The error may involve org.camunda.bpm.engine.impl.persistence.entity.HistoricVariableInstanceEntity.selectHistoricVariableInstance
### The error occurred while executing a query
### SQL: select * from ACT_HI_VARINST where ID_ = ?
### Cause: org.postgresql.util.PSQLException: This connection has been closed.

This happens only when I connect to database via pgbouncer which probably has less keep-alive time for connection than lockTimeInMillis property that I set in camunda. If I connect directly to db everything works fine.


#2

Hi @mykola,

I’m not familiar with pgbouncer. But if you have long running service tasks then you should use external tasks instead. In this case, you don’t block the process engine and don’t need to worry about open DB connections.

Does this help you?

Best regards,
Philipp


#3

Yes, I’m looking into them but we have a small problem that we use extensions to set some properties for the task and it seems difficult to get them in case of external tasks because there’s no REST method to get them. Injecting field won’t work too, of course. So, it seems that the only way is to set them into process and read from there but I have some doubts: what if we have some parallel tasks and we’ll need same properties for them but with different values. How to handle this situation with external tasks?


#4

Hi @mykola ,

you can use an input variable mapping on the external task and set the required parameter as variables. These variables are only available in the local scope of the task. So concurrency is not an issue :wink:

Best regards,
Philipp


#5

So they will be local? For some reason I thought that these variables will be set into the process and will be visible for all tasks. Thanks then!