From 709b18517717f2237b24d290095da99d0df02cf7 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Tue, 21 Aug 2018 16:16:28 +0200 Subject: [PATCH] Clear global resources reference from HttpResources When used as global Netty resources, ReactorResourceFactory creates and sets those resources on Reactor's HttpResources directly. When that ReactorResourceFactory bean is destroyed, those resources are disposed but HttpResources still holds a reference to those and may try to use them again. This commit uses HttpResources to clear those resources and its references to it, when the ReactorResourceFactory is treating those as global. Issue: SPR-17199 --- .../reactive/ReactorResourceFactory.java | 36 ++++++++++--------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java index 17e2604060..0842ff270c 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorResourceFactory.java @@ -142,25 +142,29 @@ public class ReactorResourceFactory implements InitializingBean, DisposableBean @Override public void destroy() { - - try { - ConnectionProvider provider = this.connectionProvider; - if (provider != null) { - provider.dispose(); - } - } - catch (Throwable ex) { - // ignore + if (this.globalResources) { + HttpResources.disposeLoopsAndConnections(); } + else { + try { + ConnectionProvider provider = this.connectionProvider; + if (provider != null) { + provider.dispose(); + } + } + catch (Throwable ex) { + // ignore + } - try { - LoopResources resources = this.loopResources; - if (resources != null) { - resources.dispose(); + try { + LoopResources resources = this.loopResources; + if (resources != null) { + resources.dispose(); + } + } + catch (Throwable ex) { + // ignore } - } - catch (Throwable ex) { - // ignore } }