Skip to content

Rework handling of recursive panics#110975

Merged
bors merged 2 commits into
rust-lang:masterfrom
Amanieu:panic_count
May 27, 2023
Merged

Rework handling of recursive panics#110975
bors merged 2 commits into
rust-lang:masterfrom
Amanieu:panic_count

Conversation

@Amanieu

@Amanieu Amanieu commented Apr 29, 2023

Copy link
Copy Markdown
Member

This PR makes 2 changes to how recursive panics works (a panic while handling a panic).

  1. The panic count is no longer used to determine whether to force an immediate abort. This allows code like the following to work without aborting the process immediately:
struct Double;

impl Drop for Double {
    fn drop(&mut self) {
        // 2 panics are active at once, but this is fine since it is caught.
        std::panic::catch_unwind(|| panic!("twice"));
    }
}

let _d = Double;

panic!("once");

Rustc already generates appropriate code so that any exceptions escaping out of a Drop called in the unwind path will immediately abort the process.

  1. Any panics while the panic hook is executing will force an immediate abort. This is necessary to avoid potential deadlocks like rustc hangs after ICEing due to memory limit #110771 where a panic happens while holding the backtrace lock. We don't even try to print the panic message in this case since the panic may have been caused by Display impls.

Fixes #110771

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rustc hangs after ICEing due to memory limit