Skip to content

Is this a bug when lock is timeout it throws an excption in spring-integration-redis? #2894

Closed
@Farwell-Liu

Description

@Farwell-Liu

I use spring-integration-redis for distibution lock and I found that if the lock key is expired, it will throw an exception when I unlock the lock. here is my code:

RedisLockRegistry registry = new RedisLockRegistry(getConnectionFactory(), this.registryKey);
            Lock lock = registry.obtain("foo");
            lock.lock();
            try {
                //do something that may be expired
            }
           finally {
               lock.unlock();//it throws an exception if the redis key is expired
           }
}

I read the source code of 'unlock' method in RedisLockRegistry class I found that:

if (!this.isAcquiredInThisProcess()) {
                        throw new IllegalStateException("Lock was released in the store due to expiration. The integrity of data protected by this lock may have been compromised.");
                    }

It seems that it is not a bug. I think it mislead the developers likely, at least it mislead me. so, my question is that why not just ignore case that the redis key is expired. Isn't it more friendly to developers. And then I needn't to embeded a try catch block in finally block above.

My English is not good enough probably, Did I describe my question clearly?
Could you please explain that for me? thank you very much!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions