From 8ab2d7733481ac60ef16f39ca350bf455d2a263f Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Fri, 8 Oct 2021 16:55:00 +1100 Subject: [PATCH] Fix potential request context leak The request context could be destroyed but not disasociated, resulting in an empty request context leaking. This fixes the intermittent failures in WebsocketOidcTestCase --- .../common/core/AbstractResteasyReactiveContext.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java index e8d1f3976addf..1b08a3ec8c7f1 100644 --- a/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java +++ b/independent-projects/resteasy-reactive/common/runtime/src/main/java/org/jboss/resteasy/reactive/common/core/AbstractResteasyReactiveContext.java @@ -143,9 +143,7 @@ public void run() { synchronized (this) { if (isRequestScopeManagementRequired()) { if (requestScopeActivated) { - if (position != handlers.length) { - disasociateRequestScope = true; - } + disasociateRequestScope = true; requestScopeActivated = false; } } else { @@ -176,6 +174,10 @@ public void run() { // we need to make sure we don't close the underlying stream in the event loop if the task // has been offloaded to the executor if ((position == handlers.length && !processingSuspended) || aborted) { + if (requestScopeActivated) { + requestScopeDeactivated(); + currentRequestScope.deactivate(); + } close(); } else { if (disasociateRequestScope) {