-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Make panic handling more robust #28631
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
// If this is a double panic, make sure that we print a backtrace | ||
// for this panic. Otherwise only print it if logging is enabled. | ||
if panics >= 2 || backtrace::log_enabled() { | ||
log_panic(obj, file, line) |
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 that this wants to be called unconditionally in all cases actually, backtrace::log_enabled
was actually just intended to guard the backtrace emission, not the panic message itself.
For example, if you have a panicking program with this patch and don't have RUST_BACKTRACE=1
, this means that no output will happen. (e.g. see failing Travis build for an example)
Move the panic logging code to a function separate from `on_panic` and simplify the code to decide whether the backtrace should be logged.
Move the panic handling logic from the `unwind` module to `panicking` and use a panic counter to distinguish between normal state, panics and double panics.
The double-panic `abort` is run after the logging code, to provide feedback in case of a double-panic. This means that if the panic logging fails with a panic, the `abort` might never be reached. This should not normally occur, but if the `on_panic` function detects more than 2 panics, aborting *before* logging makes panic handling somewhat more robust, as it avoids an infinite recursion, which would eventually crash the process, but also make the problem harder to debug. This handles the FIXME about what to do if the thread printing panics.
7d23165
to
54c0231
Compare
I updated the commits to fix the behaviour as pointed out by @alexcrichton and to improve the commit messages a bit. In particular now it states explicitly that the FIXME ranma42@54c0231#diff-dec9d6f114f706b628f5fcc9222f739dL55 now is handled. |
This is mainly to avoid infinite recursion and make debugging more convenient in the anomalous case in which `on_panic` panics. I encountered such issues while changing libstd to debug/fix part of #28129. While writing this I was wondering about which functions belong to `panicking` and which to `unwind`. I placed them in this way mostly because of convenience, but I would strongly appreciate guidance.
This is mainly to avoid infinite recursion and make debugging more convenient in the anomalous case in which
on_panic
panics.I encountered such issues while changing libstd to debug/fix part of #28129.
While writing this I was wondering about which functions belong to
panicking
and which tounwind
.I placed them in this way mostly because of convenience, but I would strongly appreciate guidance.