You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A NullPointerException occours in lettuce core version 6.1.10.RELEASE if the INFO-Command on a Redis cluster fails. I assume the issue will also affect 6.2.1.RELEASE, but I did not test this. We ran into this Problem when updating our application to Spring Boot 2.6.13, which updated the lettuce-core dependency.
Nearly the same issue was already reported (and fixed) with #2035, but the error appears again after the changes made for #2161.
privateintgetClientCount(Stringinfo) {
returngetMatchOrDefault(info, CONNECTED_CLIENTS_PATTERN, Integer::parseInt, 0); // <- client count is extracted from the INFO result, but 0 seems to be a valid default value
}
// ...privatestatic <T> TgetMatchOrDefault(Stringhaystack, Patternpattern, Function<String, T> converter, TdefaultValue) {
Matchermatcher = pattern.matcher(haystack); // <- this line will result in a NullPointerException// ...
}
A useful exception is thrown or (if possible) the the failed INFO command is handled in a way, that the further execution is possible without any error.
Environment
Lettuce version(s): 6.1.10.RELEASE
Redis version: 6.2
Java version: 11 and 17
Possible Solution
I'm not sure, if the result of INFO command is absolutely required.
If yes, the code should handle this case. Instead of returning null in the optionallyGet method in the case of command.isCompletedExceptionally() an exception should be thrown that gives usefull feedback and developers can handle the exception if needed or at least pin down the cause of the error.
If the INFO result is not required, optionallyGet should return Optional<T> instead of a T. In case of an error Optional.empty() should be returned. This could help to avoid NullPointerExceptions in the future, so that no null values are passed to any method that doesn't support it. I think this might be a solution since the getClientCount method has a possible default value of 0.
Since a NullPointerException was fixed in #2035 already, I suggest to avoid handling possible null values here and use Optional instead.
Additional context
There are several reasons, why the INFO request might fail. In my case the reason is not a network issue or similar. On our Redis cluster all Redis commands, that are marked as @dangerous, are blocked by an ACL rule. And the INFO command is one of these commands. I think, blocking commands of a category like @dangerous is not an uncommon scenario, it is even described in the Redis ACL documentation.
This behavior could also be reproduced by adding rename-command INFO "" to the redis config. This might be easier to reproduce this issue than handling ACL's
As a workaround we configured a temporary exception for the INFO command on our redis cluster.
The text was updated successfully, but these errors were encountered:
Bug Report
Current Behavior
A NullPointerException occours in lettuce core version 6.1.10.RELEASE if the INFO-Command on a Redis cluster fails. I assume the issue will also affect 6.2.1.RELEASE, but I did not test this. We ran into this Problem when updating our application to Spring Boot 2.6.13, which updated the
lettuce-core
dependency.Nearly the same issue was already reported (and fixed) with #2035, but the error appears again after the changes made for #2161.
If a Redis cluster is used,
lettuce-core
will send an INFO command to the cluster. See NodeTopologyView line 103 and ongoingWhen the client count is supposed to be extracted from the INFOresult, this
null
value is later passed as thehaystack
variable to Pattern#matcher(java.lang.CharSequence), which can not handlenull
values. See NodeTopologyView line 84 and ongoingSee the Stack-Trace for details:
Stack trace
Expected behavior:
A useful exception is thrown or (if possible) the the failed INFO command is handled in a way, that the further execution is possible without any error.
Environment
Possible Solution
I'm not sure, if the result of
INFO
command is absolutely required.If yes, the code should handle this case. Instead of returning
null
in theoptionallyGet
method in the case ofcommand.isCompletedExceptionally()
an exception should be thrown that gives usefull feedback and developers can handle the exception if needed or at least pin down the cause of the error.If the
INFO
result is not required,optionallyGet
should returnOptional<T>
instead of aT
. In case of an errorOptional.empty()
should be returned. This could help to avoid NullPointerExceptions in the future, so that nonull
values are passed to any method that doesn't support it. I think this might be a solution since thegetClientCount
method has a possible default value of0
.Since a NullPointerException was fixed in #2035 already, I suggest to avoid handling possible
null
values here and use Optional instead.Additional context
There are several reasons, why the
INFO
request might fail. In my case the reason is not a network issue or similar. On our Redis cluster all Redis commands, that are marked as@dangerous
, are blocked by an ACL rule. And the INFO command is one of these commands. I think, blocking commands of a category like@dangerous
is not an uncommon scenario, it is even described in the Redis ACL documentation.This behavior could also be reproduced by adding
rename-command INFO ""
to the redis config. This might be easier to reproduce this issue than handling ACL'sAs a workaround we configured a temporary exception for the
INFO
command on our redis cluster.The text was updated successfully, but these errors were encountered: