-
Notifications
You must be signed in to change notification settings - Fork 6.1k
8336384: AbstractQueuedSynchronizer.acquire should cancel acquire when failing due to a LinkageError or other errors #20548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@DougLea @AlanBateman FYI |
👋 Welcome back vklang! A progress list of the required criteria for merging this PR into |
@viktorklang-ora This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 146 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@viktorklang-ora The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
LockSupport.parkNanos(this, nanos); | ||
else | ||
break; | ||
} catch (Error ex) { // rethrow VM errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Part of me things this should be Throwable to allow for possible runtime exceptions when timed-parking virtual threads. There is a separate work needed to ensure a runtime exception is never throw but it would at least cancel here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or use (Error | RuntimeException ex)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be okay too as there are no checked exceptions here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AlanBateman If we really want it airtight I think we need to catch Throwable and sneaky-rethrow it? 🤔
LockSupport.parkNanos(this, nanos); | ||
else | ||
break; | ||
} catch (Error | RuntimeException ex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DougLea @AlanBateman Changed to Error | RuntimeException here and for AQS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catch (Throwable ex)
would be consistent with the similar block at line 331. Though I'm unclear how that compiles without the method declaring throws Throwable
??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I'm unclear how that compiles without the method declaring
throws Throwable
??
It wouldn't need that because of precise rethrow. In any case, having Error and RuntimeException are okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It has been a while since I knew this code reasonably well so perhaps I have just forgotten this difference between AQS and built-in monitors, but it seems that a Condition.await can return by throwing an exception without re-acquiring the associated synchronizer. Or is that handled at a higher-level?
The semantics are the same as monitor wait/notify so Condition.await must guarantee to hold the lock when it returns. If ConditionNode.block were to throw something like StackOverflowError then there would be an issue (it's a different park to the one changed in this PR but I think you do have a good point). |
/integrate |
Going to push as commit fbe4cc9.
Your commit was automatically rebased without conflicts. |
@viktorklang-ora Pushed as commit fbe4cc9. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
AFAICS |
The changes here just cancel the attempt to acquire before throwing. There is more to Condition.awaitXXX in that they park until they can acquire, then acquire. So SOE or some other resource error would mean awaitXXX throws without holding the lock. We have done some work to on the virtual thread implementation of LockSupport.park/parkNanos/unpark so they never fail with OOME. There is a bit more to come there but otherwise not clear how to deal with other resource errors. |
When we have |
Right now, the catch is just defending against LockSupport.park or parkNanos throwing. A timed-park on a virtual thread requires queueing a timer task and first use can involve class loading, initialisation and running more code that is obvious. We are trying to harden this as much as this as possible to never throw OOME. SOE is a lost cause. REE is possible right now and we have to do more to prevent that. Instrumentation brings a truck load of possible issues as some wild agent could instrument core classes and cause all manner of exceptions and issues. All we are doing here is just cancelling the acquire when throwing. It's just too surprising, and hard to diagnose, to throw and leaving a node queued. |
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20548/head:pull/20548
$ git checkout pull/20548
Update a local copy of the PR:
$ git checkout pull/20548
$ git pull https://git.openjdk.org/jdk.git pull/20548/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20548
View PR using the GUI difftool:
$ git pr show -t 20548
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20548.diff
Webrev
Link to Webrev Comment