Repository navigation
Description
Redis version
1.4.3
Redisson version
3.44
Redisson configuration
@bean("comSapRfmOdsLocksSpringRedissonClient")
RedissonClient redissonClient(Environment environment) {
String redisHost = environment.getProperty("redis-host");
Assert.notNull(redisHost, "Please specify a parameter redis-host");
String redisPort = environment.getProperty("redis-port");
Assert.notNull(redisPort, "Please specify a parameter redis-port");
String redisDatabase = environment.getProperty("redis-database");
Assert.notNull(redisDatabase, "Please specify a parameter redis-database");
String redisTls = environment.getProperty("redis-tls");
var redissonConfig = new Config();
String redisProtocol = Boolean.parseBoolean(redisTls) ? "rediss://" : "redis://";
var singleServerConfig = redissonConfig.useSingleServer()
.setAddress(redisProtocol + redisHost + ":" + redisPort)
.setDatabase(Integer.parseInt(redisDatabase));
String redisUsername = environment.getProperty("redis-username");
if (StringUtils.isNotEmpty(redisUsername)) {
singleServerConfig.setUsername(redisUsername);
}
String redisPassword = environment.getProperty("redis-password");
if (StringUtils.isNotEmpty(redisPassword)) {
singleServerConfig.setPassword(redisPassword);
}
redissonConfig.setLockWatchdogTimeout(30000); // 30 seconds
return Redisson.create(redissonConfig);
}
@bean("comSapRfmOdsLocksSpringLockEnvironment")
LockEnvironment lockEnvironment(@qualifier("OdsTenantProvider") Supplier tenantProvider,
RedissonClient redissonClient) {
return LockEnvironmentBuilder.create().lockTechnology(REDISSON).redissonClient(redissonClient)
.tenantProvider(tenantProvider)
.build();
}
What is the Expected behavior?
No issues during processing with locks.
What is the Actual behavior?
Hi, with the upgrade of redisson to version 3.44. we observe issues during the unlocking (see stack trace) without changing our code base. The issue does not happening in redisson releases lower then 3.44.
We are using method tryLock() of java.util.concurrent.locks to acquire a lock. In config the watchdogTimeOut is set to 30 seconds.
Was there a specific change in version 3.44. which requires also an adoption on our end?
Thanks for your help.
Best Regards
Michael
Additional information
"stacktrace": [
"java.lang.IllegalMonitorStateException: attempt to unlock lock, not locked by current thread by node id: b3ccb4a4-11ed-4997-8c1b-806fc81aa1c3 thread-id: 355705",
"\tat org.redisson.RedissonBaseLock.lambda$unlockAsync0$2(RedissonBaseLock.java:172)",
"\tat java.base/java.util.concurrent.CompletableFuture.uniHandle(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture$UniHandle.tryFire(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture.complete(Unknown Source)",
"\tat org.redisson.command.RedisExecutor.handleSuccess(RedisExecutor.java:676)",
"\tat org.redisson.command.RedisExecutor.handleResult(RedisExecutor.java:652)",
"\tat org.redisson.command.RedisExecutor.checkAttemptPromise(RedisExecutor.java:629)",
"\tat org.redisson.command.RedisExecutor.lambda$execute$5(RedisExecutor.java:209)",
"\tat java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture.complete(Unknown Source)",
"\tat io.opentelemetry.javaagent.instrumentation.redisson.CompletableFutureWrapper.lambda$new$0(CompletableFutureWrapper.java:28)",
"\tat java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture.postComplete(Unknown Source)",
"\tat java.base/java.util.concurrent.CompletableFuture.complete(Unknown Source)",
"\tat org.redisson.client.handler.CommandDecoder.completeResponse(CommandDecoder.java:535)",
"\tat org.redisson.client.handler.CommandDecoder.handleResult(CommandDecoder.java:529)",
"\tat org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:449)",
"\tat org.redisson.client.handler.CommandDecoder.decodeCommand(CommandDecoder.java:220)",
"\tat org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:148)",
"\tat org.redisson.client.handler.CommandDecoder.decode(CommandDecoder.java:124)",
"\tat io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)",
"\tat io.netty.handler.codec.ReplayingDecoder.callDecode(ReplayingDecoder.java:366)",
"\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)",
"\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)",
"\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)",
"\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)",
"\tat io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1519)",
"\tat io.netty.handler.ssl.SslHandler.decodeJdkCompatible(SslHandler.java:1377)",
"\tat io.netty.handler.ssl.SslHandler.decode(SslHandler.java:1428)",
"\tat io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)",
"\tat io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)",
"\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)",
"\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)",
"\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)",
"\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)",
"\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1357)",
"\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)",
"\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)",
"\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:868)",
"\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)",
"\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:796)",
"\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:732)",
"\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:658)",
"\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)",
"\tat io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:998)",
"\tat io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)",
"\tat io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)",
"\tat java.base/java.lang.Thread.run(Unknown Source)"
]
}
Activity
mrniko commentedon Aug 26, 2025
There was an issue "RReadWriteLock.unlock() method doesn't respect the lock owner" fixed in 3.44.0 version
mproofi commentedon Sep 2, 2025
Hi Nikita,
Thanks for your answer. Actually, I was aware of your fix in version 3.44.0.
We are “locking” and “unlocking” using the following code:
I added to logging into the code in order to be able to check if the “thread-id” is different when locking/unlocking.
So far, we see the error message “attempt to unlock lock, not locked by current thread by node id” for long running processes.
Checking the log the thread-id is same when performing the lock and the unlock, so we have no idea why this issue happens.
Do you have any recommendations to identify the root cause of the issue?
Thanks a lot for your help.
Best Regards
Michael
mrniko commentedon Sep 2, 2025
Hi,
Which Valkey or Redis vendor do you use?
mproofi commentedon Sep 3, 2025
Hi Nikita,
we currently using Azure Cache for Redis, Redis Version 6.
Regards
Michael
mrniko commentedon Sep 3, 2025
Can you confirm that there is no issue with 3.43.0 version?
mproofi commentedon Sep 9, 2025
Hi Nikita, well, in very seldom cases (in connection with a high workload) we also receive this issue in a lower redisson version.
mproofi commentedon Sep 10, 2025
Hi Nikita, for better analysis i have added now serval log messages during the process with the following result:
As you can see in the screenshots the tryLock() and unlock() are using the same thread but still we receive the "attempt to unlock" issue. I determined the thread id with
Thread.currentThread().threadId()which probably is the JVM thread id which might be different to the id redission is using internally.In azure redis we can see a lot of "expired keys" in that time frame.
But still from our side it looks like that redisson is somehow thinking or using the wrong thread to unlock even from the application the thread-id is the same.
Do you have any ideas to analyse this issue further? Is there a way to analyse the issue inside redission?
Thanks for your help and Best Regards
Michael
mrniko commentedon Sep 16, 2025
Below is the reproducer using Redisson's test environment. Reproduces the issue with bitnami/redis-cluster:7.4.1+
mproofi commentedon Sep 17, 2025
Hi Nikita, thanks for your update and your efforts. Please keep me updated in case a fix is available.
Thanks and Best Regards
Michael
Fixed - Attempt to unlock lock, not locked by current thread by node id
Merge pull request #6784 from seakider/fixed_unlock
mrniko commentedon Sep 22, 2025
merged
seakider commentedon Sep 23, 2025
Hi, @mproofi
This may be a bug where the watchdog failed to renew locks, which has been fixed in redisson-3.46.0. Can you try redisson-3.46.0 or higher version?
mproofi commentedon Sep 23, 2025
Hi seakider, i will try it with 3.46 and let you know.
Regards
Michael
mproofi commentedon Sep 24, 2025
Hi @seakider, i have retested our application with 3.46. and the "attempt to unlock" issue still persist. Therefore we really looking forward for the fix mentions above in version 3.52. Do you have a rough timeline in mind when this new version will be available for us?
Thanks and Best Regards
Michael
mrniko commentedon Sep 24, 2025
@mproofi
Hi,
During this week.
seakider commentedon Sep 24, 2025
@mproofi
In redisson-3.46.0, there was a fix for the “attempt to unlock” problem.
The changes to this issue in the upcoming redisson-3.52.0 release are for cluster environments.
If you are using a non-cluster environment, then this may be a new situation, and it would be good to provide a test case to get a demo program to help reproduce the problem.
mproofi commentedon Sep 24, 2025
Hi @seakider , thanks for the explanation. Our application runs in a cluster environment, so your fix should solve our issue.
Thanks!