Skip to content

Attempt to unlock lock, not locked by current thread by node id in redisson 3.52 #6844

Closed

Description

@mproofi

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

  1. mrniko commented on Nov 3, 2025

    @mrniko
    Member

    Can you share the code example?

  2. mproofi commented on Nov 6, 2025

    @mproofi
    Author

    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

  3. mproofi commented on Dec 12, 2025

    @mproofi
    Author

    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

  4. mrniko commented on Dec 12, 2025

    @mrniko
    Member

    There is only one reproducer we could find:

        @Test
        public void testLockFailoverInCluster() {
            withNewCluster((nodes, redisson) -> {
                for (int i = 0; i < 10; i++) {
                    RLock t = redisson.getLock("test_lock");
                    if (t.tryLock()) {
                        t.unlock();
                    }
                }
            });
        }

    Can you suggest a better one for the current version? Since we can't reproduce the issue

  5. added a commit that references this issue on Feb 11, 2026
  6. added this to the 4.2.1 milestone on Feb 11, 2026
  7. mrniko commented on Feb 11, 2026

    @mrniko
    Member

    merged

  8. mrniko commented on Feb 11, 2026

    @mrniko
    Member

    @mproofi

    Can you share a configuration or code reproducer?

  9. peterhalicky commented on Feb 24, 2026

    @peterhalicky
    Contributor

    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.

  10. mrniko commented on Feb 25, 2026

    @mrniko
    Member

    @peterhalicky

    Which Redisson version do you use?

  11. peterhalicky commented on Feb 25, 2026

    @peterhalicky
    Contributor

    @mrniko we're using 3.52

  12. modified the milestones: 4.3.0, 4.3.1 on Mar 5, 2026
  13. modified the milestones: 4.3.1, 4.3.2 on Apr 6, 2026
  14. nhancdt2602 commented on Apr 29, 2026

    @nhancdt2602
    Contributor

    @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.

  15. seakider commented on Apr 29, 2026

    @seakider
    Contributor

    @nhancdt2602
    Of course, please go ahead.

  16. nhancdt2602 commented on Apr 29, 2026

    @nhancdt2602
    Contributor

    @seakider

    Hypothesis

    There is a potential lost update problem relating to tryLock and unlock lifecycle. Given that lock RenewalTask iterates on name2Entry to refresh TTL, when a LockEntry in name2Entry is 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 before unlock operation, leading to the aforementioned exception.

    To be specific, the race condition timing diagram is as follows:

    Step Thread 1 Thread 2 RedissonLock State (name2Entry) Redis State
    1 getLock("abc") — — —
    2 tryLock() — {"abc" = LockEntry{threadsQueue=["thread1"]}} —
    3 return true — — —
    4 unlock() — — —
    5 LockRenewalScheduler.cancelExpirationRenewal() — — —
    6 LockTask.cancelExpirationRenewal() — — —
    7 task.removeThreadId() — {"abc" = LockEntry{threadsQueue=[]}} —
    8 task.hasNoThreads() = true — — —
    9 return true — — —
    10 — tryLock() — —
    11 — tryAcquireAsync() — —
    12 — tryLockInnerAsync() — —
    13 — scheduleExpirationRenewal() — —
    14 — LockRenewalScheduler.renewLock() — —
    15 — LockTask.add() {"abc" = LockEntry{threadsQueue=["thread2"]}} —
    16 name2entry.remove("abc") ⚠️ doWork... {} ← entry removed!, lost update —
    17 — doWork... {} —
    18 — doWork... {} ⚠️ lock expires! no renewal job running
    19 — unlock() {} —
    20 — IllegalMonitorStateException {} ❌ lock already expired

    Reproduce

    I am also able to reproduce this bug consistently with a help of custom instrumented RedissonLock and added isLockSetEmpty method from LockRenewalScheduler. 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.compute to ensure addition and removal operations are serialized and thread-safe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions