Closed
Description
Expected Behavior
- The
unlock()
method ofJdbcLock
should verify the execution result of releasing the lock ownership. - If the ownership can not be removed due to data expiration, a
ConcurrentModificationException
should be thrown. The RedisLock
implementation should also throw aConcurrentModificationException
in similar scenarios.
Current Behavior
- The
unlock()
method does not verify the execution result of releasing the lock ownership. - The
RedisLock
throws anIllegalStateException
when attempting to release the lock after the ownership has expired.
Context
If the unlock()
method does not verify the execution result of releasing the lock ownership, users might face concurrency issues without being notified. For example:
- Process A and process B are operating in the same region. Process A acquires the distributed lock with lock_key: 'key'.
- Due to prolonged work, the ownership of the lock held by process A expires.
- Before process A releases the lock, process B also acquires the distributed lock with same lock_key.
- When process A attempts to release the distributed lock, the current implementation does not inform the user that the integrity of data protected by this lock may have been compromised.
To address this, it is proposed that the unlock()
method be enhanced to verify if the ownership of lock has been removed successfully. If the ownership cannot be removed due to data expiration, a ConcurrentModificationException
will be thrown. This approach maintains the integrity of the distributed lock mechanism.