quarkusio/quarkus · error · ContextNotActiveException
No active context found for:
Error message
No active context found for:
What it means
Instance.destroy(Object) requires an active context for the scope of the bean being destroyed when the instance is a client proxy of a normal-scoped bean. ArC looks up the active context via Arc.requireContainer().getActiveContext(scope); if none is active it throws ContextNotActiveException. For dependent instances it destroys them directly via the CreationalContext, so this error only concerns normal-scoped proxies.
Source
Thrown at independent-projects/arc/runtime/src/main/java/io/quarkus/arc/impl/InstanceImpl.java:231
@Override
public boolean isUnsatisfied() {
return beans().isEmpty();
}
@Override
public boolean isAmbiguous() {
return beans().size() > 1;
}
@Override
public void destroy(Object instance) {
Objects.requireNonNull(instance);
if (instance instanceof ClientProxy) {
ClientProxy proxy = (ClientProxy) instance;
InjectableContext context = Arc.requireContainer().getActiveContext(proxy.arc_bean().getScope());
if (context == null) {
throw new ContextNotActiveException("No active context found for: " + proxy.arc_bean().getScope());
}
context.destroy(proxy.arc_bean());
} else {
// First try to destroy a dependent instance
if (!creationalContext.removeDependentInstance(instance, true)) {
// If not successful then try the singleton context
SingletonContext singletonContext = (SingletonContext) Arc.requireContainer().getActiveContext(Singleton.class);
singletonContext.destroyInstance(instance);
}
}
}
@Override
public InstanceHandle<T> getHandle() {
return getHandle(bean());
}
@OverrideView on GitHub (pinned to e1c734241f)
Solutions
- Only call destroy() for normal-scoped beans while their context is active (inside the request/session)
- Annotate the destroying code with @ActivateRequestContext (io.quarkus.arc) to make the request context active
- Destroy the dependent instance (not the proxy): keep the unwrapped dependent object and destroy that
- Re-architect so cleanup happens within the scope's lifecycle instead of manual destroy()
Example fix
// before (no active context in background thread)
executor.submit(() -> instance.destroy(requestScopedBean));
// after
@ActivateRequestContext
void cleanup() { instance.destroy(requestScopedBean); } Defensive patterns
Strategy: try-catch
Validate before calling
ScopeInstance scope = Arc.container().getActiveScope(bean instanceof ClientProxy
? ((ClientProxy) bean).arc_bean().getScope() : Dependent.class);
if (scope == null) throw new IllegalStateException("Context not active; cannot destroy"); Type guard
static boolean isDestroyableNow(Object instance) {
if (!(instance instanceof ClientProxy p)) return true; // dependent instances fine
return Arc.container().getActiveContext(p.arc_bean().getScope()) != null;
} Try / catch
try {
instance.destroy(bean);
} catch (ContextNotActiveException e) {
log.warnf("Context not active for %s; deferring destroy", bean);
// retry inside the proper scope or skip
} Prevention
- Never destroy normal-scoped beans from background threads without @ActivateRequestContext
- Prefer letting the container destroy beans via scope lifecycle instead of manual destroy()
- For manual cleanup, destroy the dependent (unwrapped) instance, not the client proxy
- In tests, use @ActivateRequestContext or QuarkusUnitTest so contexts are active
When it happens
Trigger: Calling injectableInstance.destroy(clientProxy) outside the scope's active window, e.g. destroying a @RequestScoped bean outside a request, a @SessionScoped bean without a session, or @ApplicationScoped after container shutdown in tests.
Common situations: Background threads/async tasks touching request-scoped instances; calling destroy() in a test without @ActivateRequestContext; cleanup code running after the CDI request context ended.
Related errors
- Producer field type is a parameterized type with a type vari
- A synthetic bean ${bean} was defined with invalid scope anno
- Declaring class of a managed bean is generic, its scope must
- Unable to destroy contextual instance of " + bean
- Cannot obtain InjectionPoint metadata for non-@Dependent bea
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/fd86a70cabbb4c4b.
Report an issue: GitHub.