Repository navigation
Description
Redis version
1.4.3
Redisson version
3.52
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,
referring to issue #6651 we have upgraded our redisson version to 3.52.0. But still sporadically the "Attempt to unlock lock" issue is occurring.
In most of the cases the issue occurs when we are processing large data packages. Processing large packages means the processing takes up to 1 minute. So the lock has to be valid during that time until the processing has finished.
In our processing we have implemented also a resilient pattern. Interesting is that in case we get an "Attempt to unlock lock" our processing is trying to reprocess the package and directly gets a new lock! So that means even if we see the message "Attempt to unlock lock ..." your internal processing seams to release the lock correctly (maybe automatically).
Still the issue does not happen 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.
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 Nov 3, 2025
Can you share the code example?
mproofi commentedon Nov 6, 2025
Hi Nikita, it still the same as shared in the prior issue: #6651 (comment)
Let me know if you need more details.
Thanks and Best Regards
Michael
mproofi commentedon Dec 12, 2025
Hi Nikita, any updates from your end? We still downgraded our redisson version to 3.43. in order to avoid this issue, which is of course not a permanent solution.
Thanks and Best Regards
Michael
mrniko commentedon Dec 12, 2025
There is only one reproducer we could find:
Can you suggest a better one for the current version? Since we can't reproduce the issue
Attempt to unlock lock, not locked by current thread by node id in re…
Merge pull request #6977 from seakider/fix_6844
mrniko commentedon Feb 11, 2026
merged
mrniko commentedon Feb 11, 2026
@mproofi
Can you share a configuration or code reproducer?
peterhalicky commentedon Feb 24, 2026
Adding my 2 cents, just so that @mproofi doesn't feel alone with this problem. We're seeing this too, very sporadically and especially when the lock is held for a longer time, but it's there.
mrniko commentedon Feb 25, 2026
@peterhalicky
Which Redisson version do you use?
peterhalicky commentedon Feb 25, 2026
@mrniko we're using 3.52
nhancdt2602 commentedon Apr 29, 2026
@seakider Could I co-work on this issue? I have a hypothesis I'd like to test, which is probably the root cause of this problem although it's rare.
seakider commentedon Apr 29, 2026
@nhancdt2602
Of course, please go ahead.
nhancdt2602 commentedon Apr 29, 2026
@seakider
Hypothesis
There is a potential lost update problem relating to
tryLockandunlocklifecycle. Given that lockRenewalTaskiterates onname2Entryto refresh TTL, when aLockEntryinname2Entryis deleted due to lost update, the lock is never renewed in background job. Hence, when a holding thread processes large work, lock key in Redis expires beforeunlockoperation, leading to the aforementioned exception.To be specific, the race condition timing diagram is as follows:
getLock("abc")tryLock(){"abc" = LockEntry{threadsQueue=["thread1"]}}return trueunlock()LockRenewalScheduler.cancelExpirationRenewal()LockTask.cancelExpirationRenewal()task.removeThreadId(){"abc" = LockEntry{threadsQueue=[]}}task.hasNoThreads() = truereturn truetryLock()tryAcquireAsync()tryLockInnerAsync()scheduleExpirationRenewal()LockRenewalScheduler.renewLock()LockTask.add(){"abc" = LockEntry{threadsQueue=["thread2"]}}name2entry.remove("abc")doWork...{}← entry removed!, lost updatedoWork...{}doWork...{}unlock(){}IllegalMonitorStateException{}Reproduce
I am also able to reproduce this bug consistently with a help of custom instrumented
RedissonLockand addedisLockSetEmptymethod fromLockRenewalScheduler. You can see PR commits for details. I split and added the test commit before fix commit so that you can run the test on your own against current implementation.Recommend Fix
I also included fix for this issue. The idea is to use
name2entry.computeto ensure addition and removal operations are serialized and thread-safefix(RLock): add and cancelExpirationRenewal race condition