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
I was testing failover scenarios and found that there is an edge case where, after initially starting and connecting to a master-replica, the number of connections in MasterReplicaConnectionProvider can be 0 and ThreadLocalRandom will throw an java.lang.IllegalArgumentException: bound must be positive.
Current Behavior
When there are 0 connections in MasterReplicaConnectionProvider, the following block of code can cause ThreadLocalRandom to throw java.lang.IllegalArgumentException: bound must be positive:
The code should probably check for a 0 value and not invoke ThreadLocalRandom.nextInt.
Also, the IllegalArgumentException is passed to io.lettuce.core.internal.Exceptions#bubble and is not wrapped:
if (throwableToUseinstanceofRuntimeException) {
return (RuntimeException) throwableToUse;
}
Why not wrap RuntimeExceptions in RedisException, which is also a RuntimeException?
Originally my code was only catching RedisException, but to be safe I am now catching Exception in places that I interact with the Lettuce command classes.
What do you think the correct behavior should be in these two situations?
Environment
Lettuce version(s): 6.1.6.RELEASE
Redis version: 6.2.5 on macOS
The text was updated successfully, but these errors were encountered:
RuntimeExceptions are propagated directly as it doesn't make sense to wrap any IAE/ISE/NPE. These exceptions are either bugs or something is odd that isn't directly tied to Redis. Thanks for looking into the matter. The mentioned code from MasterReplicaConnectionProvider assumes there's at least one node to connect to so we need to fix the bug in the client.
mp911de
changed the title
MasterReplicaConnectionProvider with zero connections causes IllegalArgumentExceptionMasterReplicaConnectionProvider with zero connections causes IllegalArgumentExceptionMar 18, 2022
Bug Report
I was testing failover scenarios and found that there is an edge case where, after initially starting and connecting to a master-replica, the number of connections in
MasterReplicaConnectionProvider
can be0
andThreadLocalRandom
will throw anjava.lang.IllegalArgumentException: bound must be positive
.Current Behavior
When there are
0
connections inMasterReplicaConnectionProvider
, the following block of code can causeThreadLocalRandom
to throwjava.lang.IllegalArgumentException: bound must be positive
:Stack trace
Expected behavior/code
The code should probably check for a
0
value and not invokeThreadLocalRandom.nextInt
.Also, the
IllegalArgumentException
is passed toio.lettuce.core.internal.Exceptions#bubble
and is not wrapped:Why not wrap
RuntimeException
s inRedisException
, which is also aRuntimeException
?Originally my code was only catching
RedisException
, but to be safe I am now catchingException
in places that I interact with the Lettuce command classes.What do you think the correct behavior should be in these two situations?
Environment
The text was updated successfully, but these errors were encountered: