Skip to content

Commit 096df01

Browse files
stuartwdouglasgsmet
authored andcommitted
De-register smallrye context manager on shutdown
Fixes #18864 (cherry picked from commit 78e5635)
1 parent 4f9bef4 commit 096df01

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

extensions/smallrye-context-propagation/deployment/src/main/java/io/quarkus/smallrye/context/deployment/SmallRyeContextPropagationProcessor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import io.quarkus.deployment.annotations.Record;
2020
import io.quarkus.deployment.builditem.ExecutorBuildItem;
2121
import io.quarkus.deployment.builditem.FeatureBuildItem;
22+
import io.quarkus.deployment.builditem.ShutdownContextBuildItem;
2223
import io.quarkus.deployment.util.ServiceUtil;
2324
import io.quarkus.smallrye.context.runtime.SmallRyeContextPropagationProvider;
2425
import io.quarkus.smallrye.context.runtime.SmallRyeContextPropagationRecorder;
@@ -67,11 +68,12 @@ void buildStatic(SmallRyeContextPropagationRecorder recorder)
6768
@Record(ExecutionTime.RUNTIME_INIT)
6869
void build(SmallRyeContextPropagationRecorder recorder,
6970
ExecutorBuildItem executorBuildItem,
71+
ShutdownContextBuildItem shutdownContextBuildItem,
7072
BuildProducer<FeatureBuildItem> feature,
7173
BuildProducer<SyntheticBeanBuildItem> syntheticBeans) {
7274
feature.produce(new FeatureBuildItem(Feature.SMALLRYE_CONTEXT_PROPAGATION));
7375

74-
recorder.configureRuntime(executorBuildItem.getExecutorProxy());
76+
recorder.configureRuntime(executorBuildItem.getExecutorProxy(), shutdownContextBuildItem);
7577

7678
// Synthetic bean for ManagedExecutor
7779
syntheticBeans.produce(

extensions/smallrye-context-propagation/runtime/src/main/java/io/quarkus/smallrye/context/runtime/SmallRyeContextPropagationRecorder.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.eclipse.microprofile.context.spi.ThreadContextProvider;
1111

1212
import io.quarkus.arc.Arc;
13+
import io.quarkus.runtime.ShutdownContext;
1314
import io.quarkus.runtime.annotations.Recorder;
1415
import io.smallrye.context.SmallRyeContextManager;
1516
import io.smallrye.context.SmallRyeContextManagerProvider;
@@ -40,7 +41,7 @@ public void configureStaticInit(List<ThreadContextProvider> discoveredProviders,
4041
builder.withContextManagerExtensions(discoveredExtensions.toArray(new ContextManagerExtension[0]));
4142
}
4243

43-
public void configureRuntime(ExecutorService executorService) {
44+
public void configureRuntime(ExecutorService executorService, ShutdownContext shutdownContext) {
4445
// associate the static init manager to the runtime CL
4546
ContextManagerProvider contextManagerProvider = ContextManagerProvider.instance();
4647
// finish building our manager
@@ -49,6 +50,12 @@ public void configureRuntime(ExecutorService executorService) {
4950
SmallRyeContextManager contextManager = builder.build();
5051

5152
contextManagerProvider.registerContextManager(contextManager, Thread.currentThread().getContextClassLoader());
53+
shutdownContext.addShutdownTask(new Runnable() {
54+
@Override
55+
public void run() {
56+
contextManagerProvider.releaseContextManager(contextManager);
57+
}
58+
});
5259
}
5360

5461
public Supplier<Object> initializeManagedExecutor(ExecutorService executorService) {

0 commit comments

Comments
 (0)