flowable / flowable/flowable-engine

ExecutorPerTenantAsyncExecutor executeAsyncJob tenant missmatch

Open
#3,223 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
7h 8m
Merged PRs (30d)
2

Description

**Describe the bug**
I am using a single process engine with a single database/shema and multiple tenants set up with a ExecutorPerTenantAsyncExecutor.

The TenantAwareAcquireAsyncJobsDueRunnable for one tenant (determined by TenantInfoHolder) will fetch jobs for multiple tenants (no where condition in [SQL](org.flowable.job.service.impl.asyncexecutor.AcquireAsyncJobsDueRunnable#acquireAndExecuteJobs), see link to forum) and will determine the asyncExecutor (ExecutorPerTenantAsyncExecutor.determineAsyncExecutor) based on the TenantInfoHolder value while the provided jobInfo might have a different tenant altogether.

This will result in executing one tenant under a thread pool for another tenant.

**Expected behavior**
The determineAsyncExecutor should take the JobInfo.tenantId into account instead of tenantInfoHolder value.

**Code**
Old:
```java
@Override
public boolean executeAsyncJob(JobInfo job) {
return determineAsyncExecutor().executeAsyncJob(job);
}
```

Idea:
```java

@Override
public boolean executeAsyncJob(JobInfo job) {
String contextTenantId = tenantInfoHolder.getCurrentTenantId();
String tenantId = StringUtils.defaultIfBlank(job.getTenantId(), contextTenantId);

if (StringUtils.isBlank(tenantId)) {
return false;
}

final AsyncExecutor asyncExecutor = tenantExecutors.get(tenantId);
if (asyncExecutor == null) {
return false;
}

return asyncExecutor.executeAsyncJob(job);
}

```

**Additional context**
Related link: https://forum.flowable.org/t/asyncjobexecutor-doesnt-work-as-expected-with-multitenancy/6424/4
Currently using flowable 6.3.1 but I think newer versions are also affected.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.