AnsweredAssumed Answered

Concurrency and REST endpoints

Question asked by lmollea on Feb 3, 2015
Latest reply on Feb 4, 2015 by lmollea
we have encountered an issue and we need to understand better what's happening.
I'll try to describe the situation then provide more info in a test case.

We have a process with two parallel execution flows. Such flows are composed of UserTask which actually get executed by remote service.
Such remote services will then complete the user tasks issuing REST calls (POST runtime/task) adding some process variables while completing the tasks.
After the 2 parallel execution flows, there is an inclusive gateway as a join point which then will activate an (embedded) subprocess where more user tasks will be activated based on the values of the variables set by the User Tasks in the previous parallel execution flows.

In an (unfortunate) concurrency case, where the complete REST calls arrived within few milliseconds between each other, we had Activiti fail in one of the two calls as it could not find some of the variables that the other transition had set.

I'll try to summarize better here what happens.

Process has Task 1 and Task 2 joining in the Inclusive Gateway 1
Inclusive Gateway 1 forks into Request A, Request B, Request C.

T1. Task 1 calls complete task, setting variables "Request_1_A" and "Request_1_B"
T2. (T0+40ms) Task 2 calls complete task, setting variables "Request_2_A" and "Request_2_C"
T3. (T0+80ms) Task 1 completes ok (probably detecting that Inclusive Gateway 1 still has a transition pending, thus just saving the variables and the transition)
T4. (T0+110ms) Task  2 fails due to an unset "Request_1_A" variable.

Requesting the process variables after T4 shows "Request_1_A" and "Request_1_B" existing while "Request_2_A" and "Request_2_C" are not.

There is a timing and/or transaction issue here and I don't know if it's a problem of how we configure the Activiti engine and its REST endpoint or how REST endpoints transaction are inherently managed.
It seems in fact that between T3 and T4, Task 2 has detected that the execution for Task 1 was not active anymore, but it could not retrieve the variables Task 1 had set and so failed to evaluate the process transitions that followed.

Only idea I have is that the REST endpoint that does a complete and a set variable do not execute under a single transaction.

Is it?
Should we split the complete calls in two, one setting the variables and then completing the task (this is surely safer) or should the REST endpoint be able to handle in a single transaction this case?