From 3577f93f91229e6ab30719a5a11be4603848c088 Mon Sep 17 00:00:00 2001 From: ren ran <35724820+stillerrr@users.noreply.github.com> Date: Sat, 27 Jan 2024 02:07:18 +0800 Subject: [PATCH] Avoid NPE in MultiNodePipelineBase (#3697) Should get connection first and then create new pipeline queue, otherwise it would cause NPE when timeout for getting connection and call sync() method. If there is timeout for getting connection, the pipeline queue would be create for node, but connections map has no connection for this node. Once executing sync() method, it would throw NPE on connection.getMany() (line 112, connection is null) --- .../java/redis/clients/jedis/MultiNodePipelineBase.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java b/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java index 10608b01f0..23ca8bc3d3 100644 --- a/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java @@ -86,9 +86,6 @@ protected final Response appendCommand(CommandObject commandObject) { queue = pipelinedResponses.get(nodeKey); connection = connections.get(nodeKey); } else { - pipelinedResponses.putIfAbsent(nodeKey, new LinkedList<>()); - queue = pipelinedResponses.get(nodeKey); - Connection newOne = getConnection(nodeKey); connections.putIfAbsent(nodeKey, newOne); connection = connections.get(nodeKey); @@ -96,6 +93,9 @@ protected final Response appendCommand(CommandObject commandObject) { log.debug("Duplicate connection to {}, closing it.", nodeKey); IOUtils.closeQuietly(newOne); } + + pipelinedResponses.putIfAbsent(nodeKey, new LinkedList<>()); + queue = pipelinedResponses.get(nodeKey); } connection.sendCommand(commandObject.getArguments());