flowable / flowable/flowable-engine
ExecutorPerTenantAsyncExecutor executeAsyncJob tenant missmatch
- Lingua principale
- Java
- Stelle
- 9.5k
- Fork
- 2.9k
- Merge medio
- 7h 8m
- PR unite (30g)
- 2
Descrizione
**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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia da ExecutorPerTenantAsyncExecutor.executeAsyncJob e verifica come TenantAwareAcquireAsyncJobsDueRunnable acquisisce i job tramite AcquireAsyncJobsDueRunnable. Riproduci il caso con un singolo database e più tenant descritto nell’issue e verifica che un job venga distribuito in base al suo JobInfo.tenantId, con il comportamento previsto coperto da un test di regressione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100