-
Bug
-
Resolution: Unresolved
-
P4
-
11, 17, 21, 22
-
None
ReentrantLock's javadoc suggests the following usage pattern:
{code:java}
* lock.lock(); // block until condition holds
* try {
* // ... method body
* } finally {
* lock.unlock()
* }
{code}
Unfortunately, {{StackOverflowError}} might result in lock being **locked** when users follow the recommendations.
The attached testcase reproduces the issue.
{noformat}
% java LockVsStackOverflow
Initial lock.isLocked() state = false
OpenJDK 64-Bit Server VM warning: Potentially dangerous stack overflow in ReservedStackAccess annotated method LockVsStackOverflow.doSmth()V [1]
FAIL: lock is LOCKED in finally, however it must be unlocked since the code did use try-finally
Exception in thread "main" java.lang.StackOverflowError
at java.base/java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:173)
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1059)
at java.base/java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:494)
at LockVsStackOverflow.doSmth(LockVsStackOverflow.java:30)
at LockVsStackOverflow.doSmth(LockVsStackOverflow.java:28)
...
{noformat}
Note: "FAIL: lock is LOCKED in finally" in the output.
I tested with
{noformat}
% java -version
openjdk version "21-ea" 2023-09-19
OpenJDK Runtime Environment (build 21-ea+30-2426)
OpenJDK 64-Bit Server VM (build 21-ea+30-2426, mixed mode, sharing)
{noformat}
{code:java}
* lock.lock(); // block until condition holds
* try {
* // ... method body
* } finally {
* lock.unlock()
* }
{code}
Unfortunately, {{StackOverflowError}} might result in lock being **locked** when users follow the recommendations.
The attached testcase reproduces the issue.
{noformat}
% java LockVsStackOverflow
Initial lock.isLocked() state = false
OpenJDK 64-Bit Server VM warning: Potentially dangerous stack overflow in ReservedStackAccess annotated method LockVsStackOverflow.doSmth()V [1]
FAIL: lock is LOCKED in finally, however it must be unlocked since the code did use try-finally
Exception in thread "main" java.lang.StackOverflowError
at java.base/java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:173)
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1059)
at java.base/java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:494)
at LockVsStackOverflow.doSmth(LockVsStackOverflow.java:30)
at LockVsStackOverflow.doSmth(LockVsStackOverflow.java:28)
...
{noformat}
Note: "FAIL: lock is LOCKED in finally" in the output.
I tested with
{noformat}
% java -version
openjdk version "21-ea" 2023-09-19
OpenJDK Runtime Environment (build 21-ea+30-2426)
OpenJDK 64-Bit Server VM (build 21-ea+30-2426, mixed mode, sharing)
{noformat}
- duplicates
-
JDK-8319309 Lock not released after stack overflow
-
- Closed
-
-
JDK-8028686 ReentrantLock calls can hang from lack of stack space
-
- Closed
-
- relates to
-
JDK-8319090 StackOverflow from ThreadLocal.set might shadow the root cause
-
- Open
-
-
JDK-8028686 ReentrantLock calls can hang from lack of stack space
-
- Closed
-
-
JDK-8046936 JEP 270: Reserved Stack Areas for Critical Sections
-
- Closed
-