From 64b5aac03bc26a1278796718a49c264d0005164f 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 a01ff4d1bb..13f2730ab4 100644 --- a/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java +++ b/src/main/java/redis/clients/jedis/MultiNodePipelineBase.java @@ -63,9 +63,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); @@ -73,6 +70,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());