-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
8303198: System and Runtime.exit() resilience to logging errors #12770
Conversation
and ignoring the exception. Exceptions in the logging will not interfere with Runtime.exit processing.
👋 Welcome back rriggs! A progress list of the required criteria for merging this PR into |
@RogerRiggs 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
|
System.err.println("Runtime.exit() logging failed: " + throwable.getMessage()); | ||
} catch (Throwable throwable2) { | ||
// Ignore | ||
} |
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.
The update means that several threads racing to exit may result in more than one message being logged. I don't think that's a big issue but just wanted to make sure that this was deliberate.
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.
Yes, its racy, and intentional, but from a diagnostic view, the developer should know that multiple callers were trying to exit. All but one will hang.
Consolidating the code in a single method is cleaner and with fewer interactions between separate code blocks.
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.
I can't tell if the thread identity will be included in the log the message?
I'm not so sure it is useful to allow competing exit calls to all log their intent. I would have kept the logging itself inside the locked region as per the original code.
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.
The main diagnostic is the logged message with the stack trace. The println version is present as a diagnostic if logging is mis-configured.
If the developer is looking to mitigate calls to Runtime.Exit, then they are advised to check all paths and will appreciate not having to wait for a different thread to win the race.
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.
But does that logging include the thread identity? If multiple threads can race to exit and all log, then the developer/user needs to know which logging came from which thread.
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.
But does that logging include the thread identity? If multiple threads can race to exit and all log, then the developer/user needs to know which logging came from which thread.
That's really up to the Logger and its configuration. If j.u.logging is used then formatters can be configured to put the thread ID into the log records. With 3rd party logging libraries there seems to be several choices, like %t for the thread name.
The main usage for this logging is to be able to find code in tests, plugins, etc. that is calling System.exit and causing the test runner or container to exit. So I think it's less about "which thread" and more about "which code".
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.
System.Logger is a facade for arbitrary user-code, commonly the log4J bridge. I routinely observe log4J throwing SecurityException's from deep within its implementation (since it is only partially implemented to handle the security manager)
System.err.println("Runtime.exit() log finder failed with: " + throwable.getMessage()); | ||
try { | ||
// Exceptions from the Logger are printed but do not prevent exit | ||
System.err.println("Runtime.exit() logging failed: " + throwable.getMessage()); |
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.
Hello Roger, do you think including the exit code in this System.err.println message would be useful too? That would then mean that if the Logger failed for whatever reason, this fallback message would at least include the exit code to provide some hints on what might have triggered the exit.
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.
Including the status is simple enough, but has little/nothing to do with why the logging call failed.
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.
Agreed - the exit code in the System.err.println fallback would merely be a last resort to provide some possible hint on what code might have triggered an exit.
Are there any more comments? |
Are you going to remove VMOutOfMemoryException001.java from the problem list? |
I'll do that a separate PR to avoid mixing the issues and solutions. |
If this gets integrated then JDK-8303057 should be closed as a duplicate, at which point the entry in the ProblemList gets orphaned. If JDK-8303057 is to be closed as a duplicate of this issue, then this issue should update the ProblemList. Otherwise you need a new issue just to do the PL update (it would make no sense for JDK-8303057 to be hijacked for that). |
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.
I still have my doubts about the actual logging strategy and the usefulness of doing it outside the lock, but won't press it. The main thing is that logRuntimeExit
can not throw an exception.
Thanks.
@RogerRiggs 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 76 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 |
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.
Thank you Roger. The changes look good to me.
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.
I think this looks okay. The main goal is to make it easy to identify the code that is calling System.exit and this seems as robust as it can be. The issue of racing exits can be looked at again, if it turns out to be interesting.
/integrate |
Going to push as commit 379f206.
Your commit was automatically rebased without conflicts. |
@RogerRiggs Pushed as commit 379f206. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Consolidate logging and handle exceptions by printing to standard error and ignoring the exception.
Exceptions while logging will not interfere with Runtime.exit.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk pull/12770/head:pull/12770
$ git checkout pull/12770
Update a local copy of the PR:
$ git checkout pull/12770
$ git pull https://git.openjdk.org/jdk pull/12770/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 12770
View PR using the GUI difftool:
$ git pr show -t 12770
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/12770.diff