I'm using this common code in my distributed locker service:
private <T> T lockAndProcessTask(String lockKey, boolean waitForLockRelease, Supplier<T> task, Supplier<T> onLockAcquireFail) {
boolean isLockAcquired = false;
RLock lock = null;
T result;
try {
val lockAcquireWaitTime = waitForLockRelease ? LOCK_ACQUIRE_WAIT_TIME_MS : 0;
try {
lock = redissonClient.getLock(lockKey);
isLockAcquired = lock.tryLock(lockAcquireWaitTime, LOCK_LEASE_TIME_MS, MILLISECONDS);
} catch (Exception e) {
log.error("Failed to lock, lockKey = {}", lockKey, e);
}
if (isLockAcquired) {
log.debug("Lock acquired, lockKey = {}", lockKey);
result = task.get();
} else {
log.debug("Failed to acquire lock, lockKey = {}", lockKey);
result = onLockAcquireFail.get();
}
} finally {
try {
if (lock != null && lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
} catch (Exception e) {
log.error("Failed to unlock, lockKey = {}", lockKey, e);
}
}
return result;
}
And getting this error when trying to unlock RLock
: lock.unlock()
Trace:
2023-05-11 21:42:22 [cs-async-358] ERROR c.w.c.s.s.DistributedLockerService - Failed to unlock, lockKey = TEST_LOCK_9000
org.redisson.client.RedisException: Unexpected exception while processing command
Caused by: java.util.concurrent.CompletionException: org.redisson.client.RedisException: ERR The user executing the script can't publish to the channel mentioned in the command script: 4dfe249c1asdvdff2dbd408626b9aff7, on @user_script:1.. channel: [id: 0xe6b7d174, L:/172.20.0.5:45526 - R:121.187.117.226/156.121.137.203:6379] command: (EVAL), promise: java.util.concurrent.CompletableFuture@22484e24[Not completed], params: [if (redis.call('hexists', KEYS[1], ARGV[3]) == 0) then return nil;end; local counter = redis.call('hincrby', KEYS[1], ARGV[3], -1); if (counter > 0) then redis.call('pexpire', KEYS[1], ARGV[2]); return 0; else redis.call('del', KEYS[1]); redis.call('publish', KEYS[2], ARGV[1]); return 1; end; return nil;, 2, TEST_LOCK_9000, redisson_lock__channel:{TEST_LOCK_9000}, 0, 3600000, 4ac2378c-7582-4f9a-9cdfa7-8a6823e4709a:57312]
at org.redisson.RedissonBaseLock.lambda$evalWriteAsync$0(RedissonBaseLock.java:228)
at java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:822)
at java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:797)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:1977)
at org.redisson.command.CommandBatchService.lambda$executeAsync$7(CommandBatchService.java:284)
at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:760)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:736)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
Do u have any ideas how to fix this?
I tried to find some info, but didn't find anything similar. My pom.xml:
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.19.3</version>
</dependency>