Skip to content

Document panic-in-panic ("double panic") behavior #1712

Open
@ehuss

Description

@ehuss
Contributor

I can't find any documentation about double panic behavior (other than https://doc.rust-lang.org/std/ops/trait.Drop.html#panics, which currently just says "will likely abort the program"). There are some subtleties about this, because some handlers will cause a hang (see rust-lang/rust#97146).

I'm not sure exactly where or how to document this. Some thoughts:

Activity

chorman0773

chorman0773 commented on Jan 13, 2025

@chorman0773
Contributor

Note that the behaviour of the default (in rustc libstd) panic handler is interesting here, and I don't know how much of that is stable or implementation detail:

  • On the first panic, it runs the panic hook, then executes the default action depending on the runtime - unwind or abort,
  • On the second panic, it enters the panic hook as well (which can cause it to reenter if it was the panic hook, rather than a destructor, that panicked for a second time), then aborts immediately.
  • If a panic happens for the third time, it just instantly aborts the process without running the panic hook.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@chorman0773

        Issue actions

          Document panic-in-panic ("double panic") behavior · Issue #1712 · rust-lang/reference