Intermittent EmptyStackException during CDI bean resolution with Weld and asynchronous jobs
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 48/100
Rechercherichtung
Start with modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/el/CdiResolver.java and compare its context reuse with Weld's AbstractWeldELResolver.lookup behavior described in the issue. Check the CDI integration's resolver registration and tests for asynchronous expression evaluation; the issue does not name a test file. Done means establishing whether shared context causes the failure and, if confirmed, providing a safe fix that preserves CDI lifecycle semantics and avoids leaving duplicate resolvers active.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Describe the bug
We encounter intermittent EmptyStackExceptions when Flowable's asynchronous job executor evaluates service-task expressions using CDI beans on WildFly.
An affected expression is:
#{myBean.myMethod()}
The relevant stacktrace is:
ERROR [org.flowable.job.service.impl.asyncexecutor.DefaultAsyncRunnableExecutionExceptionHandler] (flowable-async-job-executor-thread-2513) {} Job 342851998 failed:
org.flowable.common.engine.api.FlowableException: Error while evaluating expression: #{myBean.myMethod()}
...
Caused by: java.util.EmptyStackException
at java.base/java.util.Stack.peek(Stack.java:103)
at org.jboss.weld.module.web.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:109)
at org.jboss.weld.module.web.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:83)
at org.flowable.cdi.impl.el.CdiResolver.getValue(CdiResolver.java:97)
at org.flowable.common.engine.impl.javax.el.CompositeELResolver.getValue(CompositeELResolver.java:243)
at org.flowable.common.engine.impl.de.odysseus.el.tree.impl.ast.AstIdentifier.eval(AstIdentifier.java:95)
at org.flowable.common.engine.impl.de.odysseus.el.tree.impl.ast.AstMethod.eval(AstMethod.java:84)
at org.flowable.common.engine.impl.de.odysseus.el.tree.impl.ast.AstMethod.eval(AstMethod.java:107)
...
The outer stacktrace includes ServiceTaskExpressionActivityBehavior.execute() and ExecuteAsyncRunnable.executeJob().
MyBean is a @Named implicit @Dependent Bean
Suspected cause
In the CdiResolver implementation we inspected, an internal EL context is created in the constructor and stored as an instance field. Subsequent calls pass this same context to the CDI container's EL resolver:
getWrappedResolver().getValue(this.context, base, property);
The https://jakarta.ee/specifications/platform/11/apidocs/jakarta/el/elcontext explicitly states that ELContext is not thread-safe and should never be shared between threads. This makes the reuse of the internal context a potential concurrency issue if the same CdiResolver instance is used by multiple asynchronous job executor threads.
Weld stores its ELCreationalContextStack in that context. In Weld 6.0.4.Final, the failing line is stack.peek().get() in the @Dependent bean lookup branch.
Our hypothesis is that concurrent calls using the same CdiResolver instance share this stack. One lookup could remove an entry while another lookup is still using it, resulting in the exception.
This is currently a hypothesis based on the stacktrace and source inspection; we have not demonstrated the precise thread interleaving.
Expected behavior
Concurrent asynchronous jobs should resolve CDI beans without EmptyStackExceptions. Evaluation state should be isolated appropriately while preserving CDI scope and bean lifecycle semantics.
Code
We are considering the following workaround, which creates a fresh Flowable CdiResolver for each resolver method call:
import java.beans.FeatureDescriptor;
import java.util.Iterator;
import org.flowable.cdi.impl.el.CdiResolver;
import org.flowable.common.engine.impl.javax.el.ELContext;
import org.flowable.common.engine.impl.javax.el.ELResolver;
public final class IsolatedCdiResolver extends ELResolver {
@Override
public Object getValue(ELContext context, Object base, Object property) {
return new CdiResolver().getValue(context, base, property);
}
@Override
public Class<?> getType(ELContext context, Object base, Object property) {
return new CdiResolver().getType(context, base, property);
}
@Override
public void setValue(
ELContext context, Object base, Object property, Object value) {
new CdiResolver().setValue(context, base, property, value);
}
@Override
public boolean isReadOnly(
ELContext context, Object base, Object property) {
return new CdiResolver().isReadOnly(context, base, property);
}
@Override
public Iterator<FeatureDescriptor> getFeatureDescriptors(
ELContext context, Object base) {
return new CdiResolver().getFeatureDescriptors(context, base);
}
@Override
public Class<?> getCommonPropertyType(ELContext context, Object base) {
return new CdiResolver().getCommonPropertyType(context, base);
}
@Override
public Object invoke(
ELContext context,
Object base,
Object method,
Class<?>[] paramTypes,
Object[] params) {
return new CdiResolver().invoke(
context, base, method, paramTypes, params);
}
}
CdiJtaProcessEngineConfiguration processEngineConfiguration = new CdiJtaProcessEngineConfiguration();
processEngineConfiguration.setPreDefaultELResolvers(List.of(new IsolatedCdiResolver()));
This should provide each call with a separate internal EL context and therefore a separate Weld creational-context stack.
The workaround has not yet been activated in the affected environment, so we cannot report that it resolves the observed failures.
Additional context
Environment:
- Flowable version: 7.2.0
- WildFly version: 41.0.1
- Weld version: 6.0.4.Final
- Java version: 25
- Integration: Flowable CDI integration on WildFly (CdiJtaProcessEngineConfiguration), with the asynchronous job executor enabled.
Before applying the workaround, we would appreciate clarification on the following:
- Does the suspected sharing of the internal EL context explain this failure, and should this be fixed in Flowable's CDI integration?
- Is creating a fresh
CdiResolverfor every resolver method call a safe workaround? In particular, could it affect@Dependentbean creation/destruction, reuse of a named dependent bean within a single expression evaluation, or context state needed across resolver calls? - What is the recommended way to replace the built-in CDI resolver so that the original resolver does not remain active alongside this wrapper? Would you recommend a different workaround?
Relevant references:
- https://github.com/flowable/flowable-engine/blob/flowable-7.2.0/modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/el/CdiResolver.java
- https://github.com/weld/core/blob/6.0.4.Final/modules/web/src/main/java/org/jboss/weld/module/web/el/AbstractWeldELResolver.java
- https://jakarta.ee/specifications/platform/11/apidocs/jakarta/el/elcontext
(created with ChatGPT)
- Vorherrschende Sprache
- Java
- Sterne
- 9.6k
- Forks
- 2.9k
- Ø Merge
- 1 T. 4 Std.
- Gemergte PRs (30 T.)
- 7
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus flowable/flowable-engine
-
FlowableMultiInstanceActivityEventImpl#isSequential() typo issueEvtl. vergeben @maxim618 hat das vor 46 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
flowable/flowable-engine#4268 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Submit #999720: Flowable Flowable BPM Engine 7.x 全量;flowable5-engine (org.activiti 兼容层) 5.x import unguarded dynamic class load remote code execution🔓infoEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 25/100
flowable/flowable-engine#4314 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Flowable Flowable BPM Engine 7.x;flowable5-engine 5.x missing authorization remote code executionOffen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
flowable/flowable-engine#4313 ·
Maintainer antworten meist innerhalb von 1 Tag
-
BpmnModel#addEscalation method implement errorEvtl. wieder frei @Rohith1551 hat das vor 15 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 55/100
flowable/flowable-engine#4306 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 57/100
flowable/flowable-engine#4300 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in flowable/flowable-engine
Ähnliche Issues
-
priority: medium Review effort [1-5]: 3 status: needs-triage type: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
carlos-emr/carlos#5431 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Integration tests: jetty:run fails with WELD-001408 for CountryJpaServiceEvtl. vergeben @viniciusmachak hat das heute übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 66/100
primefaces/primefaces#15431 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
OpenAPITools/openapi-generator#25454 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Component - Build
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100