Skip to content

Commit

Permalink
Avoid long overflow in RedisSubscription.potentiallyReadMore() #2383
Browse files Browse the repository at this point in the history


Instead of incrementing the demand plus one, we now deduct one from the available data size (which is an int).
  • Loading branch information
yizhenqiang authored and mp911de committed Apr 17, 2023
1 parent 94558a7 commit b3f83e6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/main/java/io/lettuce/core/RedisPublisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ void checkOnDataAvailable() {

void potentiallyReadMore() {

if ((getDemand() + 1) > data.size()) {
/*
* getDemand() maybe is Long.MAX_VALUE,because MonoNext.NextSubscriber#request(long n) inner use the Long.MAX_VALUE,
* so maybe "getDemand() + 1" will be overflow,we use "getDemand() > data.size() - 1" replace the "(getDemand() + 1) > data.size()"
*/
if (getDemand() > data.size() - 1) {
state().readData(this);
}
}
Expand Down

0 comments on commit b3f83e6

Please sign in to comment.