Skip to content
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

Merged
merged 3 commits into from
Sep 26, 2015
Merged

Make panic handling more robust #28631

merged 3 commits into from
Sep 26, 2015

Conversation

ranma42
Copy link
Contributor

@ranma42 ranma42 commented Sep 24, 2015

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.

@rust-highfive
Copy link
Collaborator

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)
Copy link
Member

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.
@ranma42
Copy link
Contributor Author

ranma42 commented Sep 25, 2015

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.

@alexcrichton
Copy link
Member

@bors: r+ 54c0231

Thanks!

bors added a commit that referenced this pull request Sep 26, 2015
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.
@bors
Copy link
Contributor

bors commented Sep 26, 2015

⌛ Testing commit 54c0231 with merge 6645ca1...

@bors bors merged commit 54c0231 into rust-lang:master Sep 26, 2015
@ranma42 ranma42 deleted the robust-panic branch November 18, 2015 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants