From e2e68aa57200505e89b5a30006865cb0b488e6e2 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 24 May 2022 15:18:11 +0200 Subject: [PATCH] Fix resource disposal ordering in `LettuceConnectionFactory`. We now close the cluster command executor before cleaning up the connection pools so that we first release all held connections before pruning the connection pools. Previously, the pools were pruned first leading to an attempt to return the connection held by the cluster command executor causing a PoolException. Closes #2330 --- .../lettuce/LettuceConnectionFactory.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java index 38f439348..9443a5a27 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactory.java @@ -345,6 +345,15 @@ public class LettuceConnectionFactory resetConnection(); + if (clusterCommandExecutor != null) { + + try { + clusterCommandExecutor.destroy(); + } catch (Exception ex) { + log.warn("Cannot properly close cluster command executor", ex); + } + } + dispose(connectionProvider); dispose(reactiveConnectionProvider); @@ -360,15 +369,6 @@ public class LettuceConnectionFactory } } - if (clusterCommandExecutor != null) { - - try { - clusterCommandExecutor.destroy(); - } catch (Exception ex) { - log.warn("Cannot properly close cluster command executor", ex); - } - } - this.destroyed = true; }