diff --git a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ArcThreadSetupAction.java b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ArcThreadSetupAction.java index a64d3ae4d7901..7f9aa136f38e7 100644 --- a/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ArcThreadSetupAction.java +++ b/extensions/resteasy-reactive/quarkus-resteasy-reactive-common/runtime/src/main/java/io/quarkus/resteasy/reactive/common/runtime/ArcThreadSetupAction.java @@ -15,16 +15,21 @@ public ArcThreadSetupAction(ManagedContext managedContext) { @Override public ThreadState activateInitial() { - managedContext.activate(); + boolean wasActiveBefore = managedContext.isActive(); + if (!wasActiveBefore) { + managedContext.activate(); + } InjectableContext.ContextState state = managedContext.getState(); - return toThreadState(state); + return toThreadState(state, wasActiveBefore); } - private ThreadState toThreadState(InjectableContext.ContextState state) { + private ThreadState toThreadState(InjectableContext.ContextState state, boolean wasActiveBefore) { return new ThreadState() { @Override public void close() { - managedContext.destroy(state); + if (!wasActiveBefore) { + managedContext.destroy(state); + } } @Override @@ -41,6 +46,6 @@ public void deactivate() { @Override public ThreadState currentState() { - return toThreadState(managedContext.getState()); + return toThreadState(managedContext.getState(), false); } }