Skip to content

Commit

Permalink
Fixed - FairLock methods throw 'attempt to compare nil with number' e…
Browse files Browse the repository at this point in the history
…rror #4153
  • Loading branch information
Nikita Koksharov committed May 17, 2024
1 parent 4a849af commit 703f6f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
16 changes: 8 additions & 8 deletions redisson/src/main/java/org/redisson/RedissonFairLock.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ <T> RFuture<T> tryLockInnerAsync(long waitTime, long leaseTime, TimeUnit unit, l
"if firstThreadId2 == false then " +
"break;" +
"end;" +
"local timeout = tonumber(redis.call('zscore', KEYS[3], firstThreadId2));" +
"if timeout <= tonumber(ARGV[3]) then " +
"local timeout = redis.call('zscore', KEYS[3], firstThreadId2);" +
"if timeout ~= false and tonumber(timeout) <= tonumber(ARGV[3]) then " +
// remove the item from the queue and timeout set
// NOTE we do not alter any other timeout
"redis.call('zrem', KEYS[3], firstThreadId2);" +
Expand Down Expand Up @@ -162,8 +162,8 @@ <T> RFuture<T> tryLockInnerAsync(long waitTime, long leaseTime, TimeUnit unit, l
"break;" +
"end;" +

"local timeout = tonumber(redis.call('zscore', KEYS[3], firstThreadId2));" +
"if timeout <= tonumber(ARGV[4]) then " +
"local timeout = redis.call('zscore', KEYS[3], firstThreadId2);" +
"if timeout ~= false and tonumber(timeout) <= tonumber(ARGV[4]) then " +
// remove the item from the queue and timeout set
// NOTE we do not alter any other timeout
"redis.call('zrem', KEYS[3], firstThreadId2);" +
Expand Down Expand Up @@ -247,8 +247,8 @@ protected RFuture<Boolean> unlockInnerAsync(long threadId, String requestId, int
+ "if firstThreadId2 == false then "
+ "break;"
+ "end; "
+ "local timeout = tonumber(redis.call('zscore', KEYS[3], firstThreadId2));"
+ "if timeout <= tonumber(ARGV[4]) then "
+ "local timeout = redis.call('zscore', KEYS[3], firstThreadId2);"
+ "if timeout ~= false and tonumber(timeout) <= tonumber(ARGV[4]) then "
+ "redis.call('zrem', KEYS[3], firstThreadId2); "
+ "redis.call('lpop', KEYS[2]); "
+ "else "
Expand Down Expand Up @@ -328,8 +328,8 @@ public RFuture<Boolean> forceUnlockAsync() {
+ "if firstThreadId2 == false then "
+ "break;"
+ "end; "
+ "local timeout = tonumber(redis.call('zscore', KEYS[3], firstThreadId2));"
+ "if timeout <= tonumber(ARGV[2]) then "
+ "local timeout = redis.call('zscore', KEYS[3], firstThreadId2);"
+ "if timeout ~= false and tonumber(timeout) <= tonumber(ARGV[2]) then "
+ "redis.call('zrem', KEYS[3], firstThreadId2); "
+ "redis.call('lpop', KEYS[2]); "
+ "else "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,20 +924,29 @@ private <V> CompletionStage<V> poll(Codec codec, AtomicReference<Iterator<String
public <T> CompletionStage<T> handleNoSync(CompletionStage<T> stage, Supplier<CompletionStage<?>> supplier) {
CompletionStage<T> s = stage.handle((r, ex) -> {
if (ex != null) {
if (ex.getCause().getMessage() != null
&& ex.getCause().getMessage().equals("None of slaves were synced")) {
if (ex.getCause() != null
&& ex.getCause().getMessage() != null
&& ex.getCause().getMessage().equals("None of slaves were synced")) {
return supplier.get().handle((r1, e) -> {
if (e != null) {
if (ex.getCause().getMessage() != null
&& e.getCause().getMessage().equals("None of slaves were synced")) {
if (e.getCause() != null
&& e.getCause().getMessage() != null
&& e.getCause().getMessage().equals("None of slaves were synced")) {
throw new CompletionException(ex.getCause());
}
e.getCause().addSuppressed(ex.getCause());
if (e.getCause() != null) {
e.getCause().addSuppressed(ex.getCause());
} else {
e.addSuppressed(ex.getCause());
}
}
throw new CompletionException(ex.getCause());
});
} else {
throw new CompletionException(ex.getCause());
if (ex.getCause() != null) {
throw new CompletionException(ex.getCause());
}
throw new CompletionException(ex);
}
}
return CompletableFuture.completedFuture(r);
Expand Down

0 comments on commit 703f6f5

Please sign in to comment.