Parallel_execution in camunda bpmn

:heavy_multiplication_x: couldn’t complete task ef0d8525-8d85-11ec-bbb5-5e3b8bbcff61, EngineError: Response code 500 (Internal Server Error); Error: {“type”:“OptimisticLockingException”,“message”:“ENGINE-03005 Execution of ‘UPDATE ExecutionEntity[eaf5d9f3-8d85-11ec-bbb5-5e3b8bbcff61]’ failed. Entity was updated by another transaction concurrently.”}; Type: undefined

I get this error when i am executing two tasks in parallel in camunda platform, without using parallel gateway.

Can you upload your model please?

I’m going to need the model XML to look into the execution semantics

Paralleltest1.bpmn (5.9 KB)

Processing: send_email_worker.js…

Processing: msg_topic_workers.js…

Do you have any idea why this error code is happening this is happening if i am using parallel gateway too.

Paralleltest2.bpmn (5.8 KB)

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 };

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


client.subscribe("send-email", async function({ task, taskService }) {
    console.log(" in order processing service worker");
    // const processVariables = new Variables();
    // processVariables.set("processretry", 'yes');
    let rand=Math.random();
    console.log("rand variable is ",rand);
    //await taskService.handleBpmnError(task,"Email_error","Sorry we can't process order");
    await taskService.complete(task);
  // Put your business logic
  // complete the task
});```

code for send-email
const { Client, logger } = require("camunda-external-task-client-js");
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("msg-topic", async function({ task, taskService }) {
    console.log(" in order processing service worker");
    //const processVariables = new Variables();
    //processVariables.set("processretry", 'yes');
    let rand=Math.random();
    console.log("rand variable is ",rand);
    await taskService.complete(task);
  // Put your business logic
  // complete the task
});

code for msg

Please let me know why is the error coming

This error is way protecting the process from an inconstant.
The engine will only let one thread at a time perform any action on the state. If you want to ready more about this to understand it completely you should check this out:
https://docs.camunda.org/manual/latest/user-guide/process-engine/transactions-in-processes/

In the meantime by ticking async-after tickbox on the service tasks it should solve the problem.

Also i’d like to suggest you use a parallel gateway rather than having two sequence flows leaving a single task.

but i am not changing state in the task

By completing the task you’re moving the state.

In other example i have used parallel gateway and i am getting exactly same out put with it

Adding the gateway is just matter of best practice modeling -it won’t affect the error in any way.

There is some rule, I use everywhere with parallel processing:
Set async after flag on every last task of parallel threads, before parallel joint.

This rule leads, that your own code always be successful, because commit leads to stop before join. And you tell engine… Try yourself solve this, not through my own code.

Actually engine solves this super good :)) I see no optimistic locking messages at all on all parallel threads in all my models

1 Like

I read the documentation Transactions in Processes | docs.camunda.org and some other documentation also.
So what i am understanding of this async after is that save the process state until now??

So as per your statement if we are sure that our parallel states will not run into inconsistency then we can use async after on every last task of parallel gateway?
Please modify what ever you feel better for understanding.

You have to understand how commit of task works. It is not just marking current task is completed. Commit works from transaction point to transaction point, so few steps including joins can be processed in 1 transaction.
Marking async after before joint makes parallel gateway be out of transaction. Actually engine (job executor) yourself starts new transaction from this point before joint.

4 Likes