org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of 'UPDATE ExecutionEntity

I am trying to execute the simple workflow, with test 1 and test 2 as a task, under test1 one task I am setting the variable and in test2 task I am getting the same variable. when I invoke process instance getting below error after both the task are completed, as part of the retry it works fine

2019-08-29 12:46:21.499 WARN 24947 — [aTaskExecutor-1] org.camunda.bpm.engine.jobexecutor : ENGINE-14006 Exception while executing job e2674094-ca2c-11e9-91c1-1afc74d7e891:

org.camunda.bpm.engine.OptimisticLockingException: ENGINE-03005 Execution of ‘UPDATE ExecutionEntity[e2656bd2-ca2c-11e9-91c1-1afc74d7e891]’ failed. Entity was updated by another transaction concurrently.
at org.camunda.bpm.engine.impl.db.EnginePersistenceLogger.concurrentUpdateDbEntityException(EnginePersistenceLogger.java:135) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.handleOptimisticLockingException(DbEntityManager.java:499) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.checkFlushResults(DbEntityManager.java:451) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperations(DbEntityManager.java:367) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flushDbOperationManager(DbEntityManager.java:325) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager.flush(DbEntityManager.java:297) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.interceptor.CommandContext.flushSessions(CommandContext.java:208) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.interceptor.CommandContext.close(CommandContext.java:137) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:116) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.spring.SpringTransactionInterceptor$1.doInTransaction(SpringTransactionInterceptor.java:46) ~[camunda-engine-spring-7.11.0.jar:7.11.0]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:140) ~[spring-tx-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.camunda.bpm.engine.spring.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:44) ~[camunda-engine-spring-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.interceptor.ProcessApplicationContextInterceptor.execute(ProcessApplicationContextInterceptor.java:70) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:51) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobHelper.executeJob(ExecuteJobHelper.java:44) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.executeJob(ExecuteJobsRunnable.java:92) ~[camunda-engine-7.11.0.jar:7.11.0]
at org.camunda.bpm.engine.impl.jobexecutor.ExecuteJobsRunnable.run(ExecuteJobsRunnable.java:61) ~[camunda-engine-7.11.0.jar:7.11.0]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [na:1.8.0_181]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [na:1.8.0_181]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_181]

demo.bpmn (4.9 KB)

could you elaborate further, one of the tasks fails (which one, test1?) with the error and it retried or I misunderstood?
is it completed successfully at the end?

This page can be helpful for understanding the optimistic locking:

yes task1 throws above mentioned error and it retries the same task t1 again, i dont see any error.
yes it got successfully at end.

i get below error
ENGINE-03005 Execution of ‘UPDATE ExecutionEntity[be5db1b1-ca4b-11e9-b502-1afc74d7e891]’ failed. Entity was updated by another transaction concurrently.

Whenever an entity is updated in two transactions simultaneously, one of the transactions succeeds and the other fails with OptimisticLockingException, this is expected behavior for concurrent situations and nothing to worry about since the failed job will be retriggered and the operation will be retried as in you case as well. Please find more in the link below.
https://docs.camunda.org/manual/latest/user-guide/process-engine/transactions-in-processes/#optimistic-locking-in-camunda
In case you want to find which are the two transactions causing the issue, you can enable the following logging:

  • org.camunda.bpm.engine.cmd
  • org.camunda.bpm.engine.impl.persistence

and check the transactions which update the ExecutionEntity[be5db1b1-ca4b-11e9-b502-1afc74d7e891]