Skip to content

Commit 64b5aac

Browse files
authored
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)
1 parent 152d2d4 commit 64b5aac

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: src/main/java/redis/clients/jedis/MultiNodePipelineBase.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ protected final <T> Response<T> appendCommand(CommandObject<T> commandObject) {
6363
queue = pipelinedResponses.get(nodeKey);
6464
connection = connections.get(nodeKey);
6565
} else {
66-
pipelinedResponses.putIfAbsent(nodeKey, new LinkedList<>());
67-
queue = pipelinedResponses.get(nodeKey);
68-
6966
Connection newOne = getConnection(nodeKey);
7067
connections.putIfAbsent(nodeKey, newOne);
7168
connection = connections.get(nodeKey);
7269
if (connection != newOne) {
7370
log.debug("Duplicate connection to {}, closing it.", nodeKey);
7471
IOUtils.closeQuietly(newOne);
7572
}
73+
74+
pipelinedResponses.putIfAbsent(nodeKey, new LinkedList<>());
75+
queue = pipelinedResponses.get(nodeKey);
7676
}
7777

7878
connection.sendCommand(commandObject.getArguments());

0 commit comments

Comments
 (0)