Skip to content

RedisLockRegistry falsely assumes acquiring lock in runRedisMessageListenerContainer #9401

Closed
@alexpeelman

Description

@alexpeelman

In what version(s) of Spring Integration are you seeing this issue?

For example:

6.2.4 (spring-integration-redis)

Describe the bug

The runRedisMessageListenerContainer in RedisLockRegistry tries to acquire a lock without checking the return value.

RedisLockRegistry.this.lock.tryLock();

Afterwards, in the finally block the lock is released, although there is no guarantee that it was acquired. Under specific circumstances a thread ends up in releasing a lock it doesn't hold, causing the following exception:

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63) ~[tomcat-embed-core-10.1.20.jar:10.1.20]
	at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
	Caused by: java.lang.IllegalMonitorStateException: null
	at java.base/java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(Unknown Source) ~[na:na]
	at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source) ~[na:na]
	at java.base/java.util.concurrent.locks.ReentrantLock.unlock(Unknown Source) ~[na:na]
	at org.springframework.integration.redis.util.RedisLockRegistry$RedisPubSubLock.runRedisMessageListenerContainer(RedisLockRegistry.java:677) ~[spring-integration-redis-6.2.4.jar:6.2.4]

Looking at the rest of the code I assume that a "normal" lock invocation was intended instead of tryLock.

Expected behavior

Correct lock usage either with checking the outcome of tryLock() or a simple lock()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions