From 287d743427d4e912956aba86ccda8de6d4af5512 Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Fri, 14 Jun 2024 23:43:48 +0600 Subject: [PATCH] Ensure closing connection in Pipeline (#3865) even if there is an error in sync method. --- src/main/java/redis/clients/jedis/Pipeline.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/redis/clients/jedis/Pipeline.java b/src/main/java/redis/clients/jedis/Pipeline.java index 36fab65602..af6d39ee2d 100644 --- a/src/main/java/redis/clients/jedis/Pipeline.java +++ b/src/main/java/redis/clients/jedis/Pipeline.java @@ -10,6 +10,7 @@ import redis.clients.jedis.exceptions.JedisDataException; import redis.clients.jedis.graph.GraphCommandObjects; import redis.clients.jedis.params.*; +import redis.clients.jedis.util.IOUtils; import redis.clients.jedis.util.KeyValue; public class Pipeline extends PipelineBase implements DatabasePipelineCommands, Closeable { @@ -46,10 +47,12 @@ public final Response appendCommand(CommandObject commandObject) { @Override public void close() { - sync(); - - if (closeConnection) { - connection.close(); + try { + sync(); + } finally { + if (closeConnection) { + IOUtils.closeQuietly(connection); + } } }