From 20cd0e1b6c133df42ab47d93a51f81ef5a712287 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 946126a0a..58d96a465 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 @@ -364,6 +364,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); @@ -379,15 +388,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; }