Skip to content

Commit

Permalink
Avoid NPE in MultiNodePipelineBase (#3697)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
stillerrr authored Jan 26, 2024
1 parent 152d2d4 commit 64b5aac
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/main/java/redis/clients/jedis/MultiNodePipelineBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ protected final <T> Response<T> appendCommand(CommandObject<T> 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);
if (connection != newOne) {
log.debug("Duplicate connection to {}, closing it.", nodeKey);
IOUtils.closeQuietly(newOne);
}

pipelinedResponses.putIfAbsent(nodeKey, new LinkedList<>());
queue = pipelinedResponses.get(nodeKey);
}

connection.sendCommand(commandObject.getArguments());
Expand Down

0 comments on commit 64b5aac

Please sign in to comment.