I have an issue while testing parallel tasks in camunda

Paralleltest1.bpmn (7.3 KB)
The issue is that in my “msg” service task i am setting a variable in javascript.
Case:1 If the variable is already present when i reach “msg” service task and then setting the variable in “msg” service task then it shows no problem, but
Case:2 If he variable is not present when the token reach “msg” task then it shows optimise locking error.
I am unable to understand why this behaviour the engine is showing.
I am attaching my service tasks javascript.Processing: Paralleltest1.js…

Blockquote
const { Client, logger } = require(“camunda-external-task-client-js”);
const { Variables } = require(“camunda-external-task-client-js”);

const config = { baseUrl: “http://localhost:8080/engine-rest”, use: logger };

const client = new Client(config);

client.subscribe(“send-email”, async function({ task, taskService }) {
console.log(" in order processing send email worker");
let rand=Math.random();
console.log("rand variable is ",rand);
await taskService.handleBpmnError(task,“Email_error”,“error while sending email”);
});

client.subscribe(“Slack-topic”, async function({ task, taskService }) {
console.log(" in slack toopic worker");
let rand=Math.random();
console.log("rand variable is ",rand);
await taskService.complete(task);
});

client.subscribe(“msg-topic”, async function({ task, taskService }) {
console.log(" in msg-topic");
const processVariables = new Variables();
processVariables.set(‘name’,‘gupta’);
let rand=Math.random();
console.log("rand variable is ",rand);
await taskService.complete(task,processVariables);
});

Error is that if i set a variable(name = xyz) in my user task(on starting) ,then my parallel service tasks shows no problem ,but when i did not set any variable in my user task then it shows optimistic locking error.
i have checked async after and before in all service task.

I think error is because of intermidiate error event. in sent_email

couldn’t complete task f009c3d5-8f50-11ec-8453-da6d4119fb46, EngineError: Response code 500 (Internal Server Error); Error: {“type”:“OptimisticLockingException”,“message”:“ENGINE-03005 Execution of ‘UPDATE ExecutionEntity[ed7c621a-8f50-11ec-8453-da6d4119fb46]’ failed. Entity was updated by another transaction concurrently.”}; Type: undefined this was the error

Paralleltest3.bpmn (6.9 KB)

In this i am getting optimistic lock error, If i am changing state in both parallel tasks, if i do not change state in both tasks then it does not give error. I have set async before/after flag on tasks, so it should not show optimistic error for the first case also right??.

Please correct me in this case,Look at the code (i am using for external tasks in avobe bpmn) if you want but the issue only is in concept.

const { Variables } = require("camunda-external-task-client-js");

// configuration for the Client:
//  - 'baseUrl': url to the Process Engine
//  - 'logger': utility to automatically log important events
const config = { baseUrl: "http://localhost:8080/engine-rest", use: logger };

// create a Client instance with custom configuration
const client = new Client(config);

// susbscribe to the topic: 'creditScoreChecker'

client.subscribe("Start-app", async function({ task, taskService }) {
 console.log(" in Intitiate-msg");
 //const variables = new Variables();
 //variables.set("name",'ch');
 //let rand=Math.random();
 //console.log("rand variable is ",rand);
 await taskService.complete(task);
 //await taskService.complete(task,variables);
// Put your business logic
// complete the task
});

client.subscribe("Topic-msg", async function({ task, taskService }) {
   console.log(" in msg-topic");
   const variables = new Variables();
   variables.set("na", 'vineet');
   await taskService.complete(task,variables);
   //await taskService.complete(task);
 // Put your business logic
 // complete the task
});

client.subscribe("Topic-email", async function({ task, taskService }) {
   console.log(" in set_varables");
   const processVariables = new Variables();
   processVariables.set("name", 'yes');
   let rand=Math.random();
   console.log("rand variable is ",rand);
   await taskService.complete(task,processVariables);
 // Put your business logic
 // complete the task
});

client.subscribe("Topic-ending", async function({ task, taskService }) {
   console.log(" in ending");
   const processVariables = new Variables();
   processVariables.set("freind", 'yash');
   let rand=Math.random();
   console.log("rand variable is ",rand);
   await taskService.complete(task,processVariables);
 // Put your business logic
 // complete the task
});

Hey @Vineet_Gupta1 ,

First of all, if you use External Tasks there is no need to set an async. before a task. The External Task has a natural transaction boundary. Also if it is followed by a task that has again a natural wait state it does not make that much sense to use the async. after.

When exactly do you get this error message? From the error it looks like that the External Task was completed by another worker. Could that be possible?

Kind regards
Nele

I am running only this file in one terminal , so there is only one worker for each task.
This the error
:heavy_multiplication_x: couldn’t complete task ea74cd0a-8fd2-11ec-9a52-060ae2995c79, EngineError: Response code 500 (Internal Server Error); Error: {“type”:“OptimisticLockingException”,“message”:“ENGINE-03005 Execution of ‘UPDATE ExecutionEntity[ea57a80a-8fd2-11ec-9a52-060ae2995c79]’ failed. Entity was updated by another transaction concurrently.”}; Type: undefined

Hi @Vineet_Gupta1,

what about marking only the parallel joining gateway as Asynchronous before?

You may get an Optimistic locking exception as well, but the process instance will continue with the automatic retry mechanism.

Hope this helps, Ingo

Yes the tasks is retreid after optimistic locking, but i want to run those task in parallel. For my use case both these task can be 30 min long.

What other then this i need to do to run external tasks in parallel( those are setting some state variables).

Case: as shown in fig I have a external service task just after starting, then a parallel gateway then two external tasks then end of parallel gateway, then a external service task followed by a user taks.
Part A: If i do not set any variable in first service task and then i set a variable in any one of the parallel service task the error does not come.
Part B: I i set two variables in first task (say : {name:vineet , age:20}) and then set in both parallel task i set variables (name and age) then again no error comes.
Part C: i did not set any variable in first task and then setting variables in both parallel tasks error apperas.??
What is happenning i can’t understand please let me know is it a expected behabiour for above bpmn xml code and javascript workers.