ENGINE-16004 Exception while closing command context: Cannot find task with id X: task is null

Hi ,
I have following issue . From time to time i get error engine message when i try get task identity links.
My scenario is :
I have following process :

In parallel multi instance sub process i create user task to provide missing email address . On create user task event in camunda module i use bpm.engine.delegate.TaskListener and send information to external java application about new task . Java Application call camunda api to get task ( always successfully) ,then i want to get information about groups and i call camunda appi to get identity links and sometimes i get error as in topic.

As i understand issue here is connected with transaction .Identity task links is keep in different table in camunda and when i asked about identity transation is not finished yet so i get error ’ Cannot find task with id X: task is null’. I dont understand why i can get information about task successfully but i cant get identity links. its means that insert operation for this 2 tables are call in 2 different transaction in camunda .
I don`t know how to solve it but the best solution will be have a one transaction which insert task data to all task related tables and after this catch event and send to external application.

Other solution which i think is get groups from DelegateTask on task listener for create event and pass this to java app . Something like this :

public class MyTaskCreateListener implements TaskListener {

  public void notify(DelegateTask delegateTask) {
      delegateTask.getCandidates().toString());
  }
}

but i`m not sure if this will solve issue - if DelegateTask passed in interface are a independent of database transaction and information about groups will be passed event if db transaction on identity links table is not committed yet?

Do You have any idea ?

Thanks

any ideas ?

Thanks

@gianfranco can you upload your bpmn model?

Have you configured the listener as Java Class or Delegate Expression ? Camunda spring boot setup?

Hi,
Bpmn example in attachment . I implement listener directly in camunda module( module is run as spring boot app) where we catch events like created/assign user task, so we don`t have listener attached directly for user task in bpmn model . Listener send information about task to kafka topic and topic is handled by java application where we call camunda rest api to get information about groups and i sometimes get this issue “ENGINE-16004 Exception while closing command context: Cannot find task with id X: task is null”. Probably because camunda db transaction is not commited yet in identity service table .So maybe i should get candidates from DelegateTask ( delegateTask.getCandidates()) and pass them to kafka topic?. In attachment You will find example code with our listener .

Thank you for your interest.

usertasklistenerExample.txt (933 Bytes)

GenerateReport.bpmn (11.7 KB)