From 0c7743c03e25521d7c7ddb90bc76d36ee2cb6608 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Mon, 24 Jun 2024 14:26:46 +0300 Subject: [PATCH] Fixed - password shouldn't be printed in logs. #5984 --- .../org/redisson/client/RedisConnection.java | 2 +- .../redisson/client/protocol/CommandData.java | 3 +- .../org/redisson/command/RedisExecutor.java | 32 +++++++++---------- .../command/RedisQueuedBatchExecutor.java | 4 +-- .../java/org/redisson/misc/LogHelper.java | 6 ++-- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/redisson/src/main/java/org/redisson/client/RedisConnection.java b/redisson/src/main/java/org/redisson/client/RedisConnection.java index 236e5198e..e88fa0439 100644 --- a/redisson/src/main/java/org/redisson/client/RedisConnection.java +++ b/redisson/src/main/java/org/redisson/client/RedisConnection.java @@ -249,7 +249,7 @@ public class RedisConnection implements RedisCommands { } Timeout scheduledFuture = redisClient.getTimer().newTimeout(t -> { - RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout for command: " + RedisTimeoutException ex = new RedisTimeoutException("Command execution timeout for " + LogHelper.toString(command, params) + ", Redis client: " + redisClient); promise.completeExceptionally(ex); }, timeout, TimeUnit.MILLISECONDS); diff --git a/redisson/src/main/java/org/redisson/client/protocol/CommandData.java b/redisson/src/main/java/org/redisson/client/protocol/CommandData.java index c8075b6ff..410d2e667 100644 --- a/redisson/src/main/java/org/redisson/client/protocol/CommandData.java +++ b/redisson/src/main/java/org/redisson/client/protocol/CommandData.java @@ -93,8 +93,7 @@ public class CommandData implements QueueCommand { @Override public String toString() { - return "CommandData [promise=" + promise + ", command=" + command + ", params=" - + LogHelper.toString(params) + ", codec=" + codec + "]"; + return "CommandData [command=" + LogHelper.toString(this) + ", codec=" + codec + "]"; } @Override diff --git a/redisson/src/main/java/org/redisson/command/RedisExecutor.java b/redisson/src/main/java/org/redisson/command/RedisExecutor.java index e86d33fe6..cd4b5a502 100644 --- a/redisson/src/main/java/org/redisson/command/RedisExecutor.java +++ b/redisson/src/main/java/org/redisson/command/RedisExecutor.java @@ -227,7 +227,7 @@ public class RedisExecutor { exception = new RedisTimeoutException("Unable to acquire connection! " + this.connectionFuture + "Increase connection pool size or timeout. " + "Node source: " + source - + ", command: " + LogHelper.toString(command, params) + + ", " + LogHelper.toString(command, params) + " after " + attempt + " retry attempts"); attemptPromise.completeExceptionally(exception); @@ -250,7 +250,7 @@ public class RedisExecutor { "Check CPU usage of the JVM. Check that there are no blocking invocations in async/reactive/rx listeners or subscribeOnElements method. Check connection with Redis node: " + connectionFuture.join().getRedisClient().getAddr() + " for TCP packet drops. Try to increase nettyThreads setting. " + " Node source: " + source + ", connection: " + connectionFuture.join() - + ", command: " + LogHelper.toString(command, params) + + ", " + LogHelper.toString(command, params) + " after " + attempt + " retry attempts"); attemptPromise.completeExceptionally(exception); } @@ -276,7 +276,7 @@ public class RedisExecutor { exception = new RedisTimeoutException("Unable to acquire connection! " + connectionFuture + "Increase connection pool size. " + "Node source: " + source - + ", command: " + LogHelper.toString(command, params) + + ", " + LogHelper.toString(command, params) + " after " + attempt + " retry attempts"); } else { if (connectionFuture.isDone() && !connectionFuture.isCompletedExceptionally()) { @@ -288,7 +288,7 @@ public class RedisExecutor { "Check CPU usage of the JVM. Check that there are no blocking invocations in async/reactive/rx listeners or subscribeOnElements method. Check connection with Redis node: " + getNow(connectionFuture).getRedisClient().getAddr() + " for TCP packet drops. Try to increase nettyThreads setting. " + " Node source: " + source + ", connection: " + getNow(connectionFuture) - + ", command: " + LogHelper.toString(command, params) + + ", " + LogHelper.toString(command, params) + " after " + attempt + " retry attempts"); } attemptPromise.completeExceptionally(exception); @@ -330,8 +330,8 @@ public class RedisExecutor { attempt++; if (log.isDebugEnabled()) { - log.debug("attempt {} for command {} and params {} to {}", - attempt, command, LogHelper.toString(params), source); + log.debug("attempt {} for {} to {}", + attempt, LogHelper.toString(command, params), source); } mainPromiseListener = null; @@ -363,7 +363,7 @@ public class RedisExecutor { exception = new WriteRedisConnectionException( "Unable to write command into connection! Check CPU usage of the JVM. Try to increase nettyThreads setting. Node source: " + source + ", connection: " + connection + - ", command: " + LogHelper.toString(command, params) + ", " + LogHelper.toString(command, params) + " after " + attempt + " retry attempts", future.cause()); tryComplete(attemptPromise, exception); return; @@ -379,8 +379,8 @@ public class RedisExecutor { attempt++; if (log.isDebugEnabled()) { - log.debug("attempt {} for command {} and params {} to {}", - attempt, command, LogHelper.toString(params), source); + log.debug("attempt {} for {} to {}", + attempt, LogHelper.toString(command, params), source); } mainPromiseListener = null; @@ -428,8 +428,8 @@ public class RedisExecutor { connectionManager.getServiceManager().newTimeout(t -> { attempt++; if (log.isDebugEnabled()) { - log.debug("response timeout. new attempt {} for command {} and params {} node {}", - attempt, command, LogHelper.toString(params), source); + log.debug("response timeout. new attempt {} for {} node {}", + attempt, LogHelper.toString(command, params), source); } mainPromiseListener = null; @@ -443,7 +443,7 @@ public class RedisExecutor { + " after " + attempt + " retry attempts," + " is non-idempotent command: " + (command != null && command.isNoRetry()) + " Check connection with Redis node: " + connection.getRedisClient().getAddr() + " for TCP packet drops or bandwidth limits. " - + " Try to increase nettyThreads and/or timeout settings. Command: " + + " Try to increase nettyThreads and/or timeout settings. " + LogHelper.toString(command, params) + ", channel: " + connection.getChannel())); }; @@ -667,8 +667,8 @@ public class RedisExecutor { if (connection instanceof RedisPubSubConnection) { connectionType = " pubsub "; } - log.debug("acquired{}connection for command {} and params {} from slot {} using node {}... {}", - connectionType, command, LogHelper.toString(params), source, connection.getRedisClient().getAddr(), connection); + log.debug("acquired{}connection for {} from slot {} using node {}... {}", + connectionType, LogHelper.toString(command, params), source, connection.getRedisClient().getAddr(), connection); } writeFuture = connection.send(new CommandData<>(attemptPromise, codec, command, params)); @@ -707,8 +707,8 @@ public class RedisExecutor { connectionType = " pubsub "; } - log.debug("connection{}released for command {} and params {} from slot {} using connection {}", - connectionType, command, LogHelper.toString(params), source, connection); + log.debug("connection{}released for {} from slot {} using connection {}", + connectionType, LogHelper.toString(command, params), source, connection); } } diff --git a/redisson/src/main/java/org/redisson/command/RedisQueuedBatchExecutor.java b/redisson/src/main/java/org/redisson/command/RedisQueuedBatchExecutor.java index bd6e2d4f1..74f55700e 100644 --- a/redisson/src/main/java/org/redisson/command/RedisQueuedBatchExecutor.java +++ b/redisson/src/main/java/org/redisson/command/RedisQueuedBatchExecutor.java @@ -169,8 +169,8 @@ public class RedisQueuedBatchExecutor extends BaseRedisBatchExecutor writeFuture = connection.send(new CommandsData(main, list, true, syncSlaves)); } else { if (log.isDebugEnabled()) { - log.debug("acquired connection for command {} and params {} from slot {} using node {}... {}", - command, LogHelper.toString(params), source, connection.getRedisClient().getAddr(), connection); + log.debug("acquired connection for {} from slot: {} using node: {}... {}", + LogHelper.toString(command, params), source, connection.getRedisClient().getAddr(), connection); } if (connectionEntry.isFirstCommand()) { diff --git a/redisson/src/main/java/org/redisson/misc/LogHelper.java b/redisson/src/main/java/org/redisson/misc/LogHelper.java index 44088b078..09dd0532e 100644 --- a/redisson/src/main/java/org/redisson/misc/LogHelper.java +++ b/redisson/src/main/java/org/redisson/misc/LogHelper.java @@ -37,9 +37,9 @@ public final class LogHelper { public static String toString(RedisCommand command, Object... params) { if (RedisCommands.AUTH.equals(command)) { - return command + ", params: (password masked)"; + return "command: " + command + ", params: (password masked)"; } - return command + ", params: " + LogHelper.toString(params); + return "command: " + command + ", params: " + LogHelper.toString(params); } public static String toString(Object object) { @@ -56,7 +56,7 @@ public final class LogHelper { if (RedisCommands.AUTH.equals(cd.getCommand())) { return cd.getCommand() + ", params: (password masked)"; } - return cd.getCommand() + ", promise: " + cd.getPromise() + ", params: " + LogHelper.toString(cd.getParams()); + return cd.getCommand() + ", params: " + LogHelper.toString(cd.getParams()) + ", promise: " + cd.getPromise(); } else if (object instanceof ByteBuf) { final ByteBuf byteBuf = (ByteBuf) object; // can't be used due to Buffer Leak error is appeared in log