-
Bug
-
Resolution: Done
-
Major
-
2.12
-
None
I have been trying out the new LockService class, which has been great to use.
However I began looking into stuff around interrupts, and while glancing at the actual protocol code I became a little confused as to how the lock method would ignore an interrupt and still acquire the lock. So I wrote up a simple test case, which can be found in the Reproduce section.
Needless to say the lock method behaves completely differently than how I would have expected if an interrupt was encountered. If the interrupt flag is set the lock method would return immediately, making the caller think the lock was retrieved. However the lock was not retrieved! Also not to mention the interrupt status was lost completely, further preventing the interrupt from being checked in a later part of code.
Also the tryLock() method behaves somewhat in a similar fashion as lock. If the interrupt status is set it will return false immediately and clear the interrupt status. I would expect the code to still retrieve the lock if possible and leave the interrupt flag set afterwards just like I would in the case of lock.
I did also test the lockInterruptibly, tryLock(long, TimeUnit) and those worked if the interrupt flag was set before invoking it, by throwing an InterruptedException as expected.
I didn't test any of the methods in regards to an interrupt being done in the middle of waiting to acquire a lock.