Skip to content

Very confusing error message when panicking during a panic #114954

Closed
@SUPERCILEX

Description

@SUPERCILEX
Contributor

I tried this code:

struct Foo;

impl Drop for Foo {
    fn drop(&mut self) {
        panic!("drop");
    }
}

fn main() {
    let f = Foo;
    panic!("main");
}
9  | / fn main() {
10 | |     let f = Foo;
11 | |     panic!("main");
12 | | }
   | |_^ panic in a function that cannot unwind

Clearly the function panics so the error message doesn't make much sense. I believe it's saying that while panicking, the function is placed into a context in which nested panics are disallowed. Perhaps the message could include a hint that says something like Possibly caused by nested panics from a drop function.

Activity

added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Aug 18, 2023
SUPERCILEX

SUPERCILEX commented on Aug 18, 2023

@SUPERCILEX
ContributorAuthor
SUPERCILEX

SUPERCILEX commented on Aug 18, 2023

@SUPERCILEX
ContributorAuthor

Mmmm, actually this doesn't have anything to do with miri. Simply executing this code produces thread caused non-unwinding panic. aborting.. It'd be nice if these error messages could hint that the problem may be a panic inside a drop function while handling another panic. Took me a while to figure out that bug for code I was working on.

changed the title [-]Very confusing error message from Miri when panicking during a panic[/-] [+]Very confusing error message when panicking during a panic[/+] on Aug 18, 2023
asquared31415

asquared31415 commented on Aug 18, 2023

@asquared31415
Contributor

This changed in 1.71:

1.70.0 output:

thread 'main' panicked at 'main', /app/example.rs:11:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'drop', /app/example.rs:5:9
stack backtrace:
<panic impl>
  12:     0x55850c75f2e6 - std::sys_common::backtrace::__rust_end_short_backtrace::hc203444fb7416a16
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:150:18
  13:     0x55850c760382 - rust_begin_unwind
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/panicking.rs:578:5
  14:     0x55850c747f43 - core::panicking::panic_fmt::h0f6ef0178afce4f2
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/panicking.rs:67:14
  15:     0x55850c748589 - <example::Foo as core::ops::drop::Drop>::drop::h393280156e206bc4
                               at /app/example.rs:5:9
  16:     0x55850c748589 - core::ptr::drop_in_place<example::Foo>::h69e3b7c38057fb9a
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ptr/mod.rs:490:1
  17:     0x55850c7485e0 - example::main::h69ec135913889ca2
                               at /app/example.rs:12:1
  18:     0x55850c748623 - core::ops::function::FnOnce::call_once::he901fc162f15c821
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/core/src/ops/function.rs:250:5
  19:     0x55850c748623 - std::sys_common::backtrace::__rust_begin_short_backtrace::hd136515e50fde4e6
                               at /rustc/90c541806f23a127002de5b4038be731ba1458ca/library/std/src/sys_common/backtrace.rs:134:18
<start impl>
thread panicked while panicking. aborting.

1.71.0 output:

thread 'main' panicked at 'main', /app/example.rs:11:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'drop', /app/example.rs:5:9
stack backtrace:
<panic impl>
  13:     0x55f78aa65306 - std::sys_common::backtrace::__rust_end_short_backtrace::h1410008071796261
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:151:18
  14:     0x55f78aa66162 - rust_begin_unwind
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
  15:     0x55f78aa4ce93 - core::panicking::panic_fmt::ha0a42a25e0cf258d
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:67:14
  16:     0x55f78aa4d60f - <example::Foo as core::ops::drop::Drop>::drop::hf6598d2a8a8b819e
                               at /app/example.rs:5:9
  17:     0x55f78aa4d60f - core::ptr::drop_in_place<example::Foo>::h0d465081db81d2a5
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ptr/mod.rs:497:1
  18:     0x55f78aa4d666 - example::main::h5848d682d5469a37
                               at /app/example.rs:12:1
  19:     0x55f78aa4d5c3 - core::ops::function::FnOnce::call_once::h0264184e1d2bb69c
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:250:5
  20:     0x55f78aa4d5c3 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha41bc7dc1ab08e83
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:135:18
<start impl>
thread 'main' panicked at 'panic in a function that cannot unwind', library/core/src/panicking.rs:126:5
stack backtrace:
<panic impl>
  13:     0x55f78aa65306 - std::sys_common::backtrace::__rust_end_short_backtrace::h1410008071796261
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:151:18
  14:     0x55f78aa66162 - rust_begin_unwind
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/panicking.rs:593:5
  15:     0x55f78aa4ced3 - core::panicking::panic_nounwind_fmt::h80a99c33c4703954
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:96:14
  16:     0x55f78aa4cf77 - core::panicking::panic_nounwind::h81a1bb4a16bcd655
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:126:5
  17:     0x55f78aa4d013 - core::panicking::panic_cannot_unwind::hc3ef110419ba8f94
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/panicking.rs:188:5
  18:     0x55f78aa4d66e - example::main::h5848d682d5469a37
                               at /app/example.rs:9:1
  19:     0x55f78aa4d5c3 - core::ops::function::FnOnce::call_once::h0264184e1d2bb69c
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/core/src/ops/function.rs:250:5
  20:     0x55f78aa4d5c3 - std::sys_common::backtrace::__rust_begin_short_backtrace::ha41bc7dc1ab08e83
                               at /rustc/8ede3aae28fe6e4d52b38157d7bfe0d3bceef225/library/std/src/sys_common/backtrace.rs:135:18
<start impl>
thread caused non-unwinding panic. aborting.

1.71.0 stabilized C-unwind in #106075 (feature tracked in #74990), and that's what I expect this change to bisect to (though I haven't done any actual bisection)

It would be nice if the old message could be restored, the message "thread panicked while panicking. aborting." is significantly more clear. The extra backtrace also isn't super nice.

SUPERCILEX

SUPERCILEX commented on Aug 18, 2023

@SUPERCILEX
ContributorAuthor

A combination of those error messages would be great too.

RalfJung

RalfJung commented on Aug 18, 2023

@RalfJung
Member
RalfJung

RalfJung commented on Aug 18, 2023

@RalfJung
Member

I think the origin of the behavior change is #110975, and this is probably known, but maybe something can be done to improve the error.

Cc @Amanieu

Amanieu

Amanieu commented on Aug 20, 2023

@Amanieu
Member

Currently the compiler does not differentiate between an unwind in a landing pad (recursive panic) and an unwind from a function that cannot unwind (extern "C"). It might be possible to handle these slightly differently so they produce different panic messages.

RalfJung

RalfJung commented on Aug 20, 2023

@RalfJung
Member

Well, unwind in a landing pad itself doesn't show that same error. It's the double-panic that triggers the error.

Here's the full error:

thread 'main' panicked at src/main.rs:11:5:
main
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at src/main.rs:5:9:
drop
stack backtrace:
   0:     0x562b11e2b2fc - std::backtrace_rs::backtrace::libunwind::trace::hcccbe357f6294ee4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x562b11e2b2fc - std::backtrace_rs::backtrace::trace_unsynchronized::h2aeedc764cf5993d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x562b11e2b2fc - std::sys_common::backtrace::_print_fmt::h5253f13953735ceb
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x562b11e2b2fc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h10e03889795ce36f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x562b11e4aecc - core::fmt::rt::Argument::fmt::hb786e11d88f815da
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/rt.rs:138:9
   5:     0x562b11e4aecc - core::fmt::write::h8196208c7c3ea798
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/mod.rs:1094:21
   6:     0x562b11e28fce - std::io::Write::write_fmt::hdd2d932fce82b22e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/io/mod.rs:1714:15
   7:     0x562b11e2b0e4 - std::sys_common::backtrace::_print::hee67efbbcef8ebe2
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x562b11e2b0e4 - std::sys_common::backtrace::print::h1f9d56503b146d30
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x562b11e2c87a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h863c0efb88e46827
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:278:22
  10:     0x562b11e2c567 - std::panicking::panic_hook_with_disk_dump::h7a9bb486f3291dc7
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:312:9
  11:     0x562b11e2ce7b - std::panicking::default_hook::h7e8caec6028d8d9d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:239:5
  12:     0x562b11e2ce7b - std::panicking::rust_panic_with_hook::h83c27eadec9ef70a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:729:13
  13:     0x562b11e2cd31 - std::panicking::begin_panic_handler::{{closure}}::hd577ca9f8724d099
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:619:13
  14:     0x562b11e2b826 - std::sys_common::backtrace::__rust_end_short_backtrace::h5a1a2830cb802d5e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:170:18
  15:     0x562b11e2cac2 - rust_begin_unwind
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:617:5
  16:     0x562b11e0ee33 - core::panicking::panic_fmt::h0645525d32fb8666
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:67:14
  17:     0x562b11e0f729 - <playground::Foo as core::ops::drop::Drop>::drop::hb5cf5518153c0058
                               at /playground/src/main.rs:5:9
  18:     0x562b11e0f6ca - core::ptr::drop_in_place<playground::Foo>::h10bed791575028cd
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ptr/mod.rs:497:1
  19:     0x562b11e0f756 - playground::main::h3a7c7f175b3be352
                               at /playground/src/main.rs:12:1
  20:     0x562b11e0f6bb - core::ops::function::FnOnce::call_once::hacc5d76449aef962
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:250:5
  21:     0x562b11e0f50e - std::sys_common::backtrace::__rust_begin_short_backtrace::h8e74152d9bd2457f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:154:18
  22:     0x562b11e0f581 - std::rt::lang_start::{{closure}}::h3d7d79b4aed530fe
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:166:18
  23:     0x562b11e26b7b - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hadefdea4fbcf6398
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:284:13
  24:     0x562b11e26b7b - std::panicking::try::do_call::haa16a0bcad25b40d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  25:     0x562b11e26b7b - std::panicking::try::h9367aba29c754779
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  26:     0x562b11e26b7b - std::panic::catch_unwind::h4021f90141f42c42
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  27:     0x562b11e26b7b - std::rt::lang_start_internal::{{closure}}::hff568c1c1264e3e9
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:48
  28:     0x562b11e26b7b - std::panicking::try::do_call::ha9e4f3477463e2d1
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  29:     0x562b11e26b7b - std::panicking::try::hac29284aba256fb6
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  30:     0x562b11e26b7b - std::panic::catch_unwind::h985169b2a86bf7f4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  31:     0x562b11e26b7b - std::rt::lang_start_internal::h23bd64986d4ee27a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:20
  32:     0x562b11e0f55a - std::rt::lang_start::hc617a4fa67be1c4d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:165:17
  33:     0x562b11e0f7be - main
  34:     0x7f7403a7e083 - __libc_start_main
  35:     0x562b11e0f43e - _start
  36:                0x0 - <unknown>
thread 'main' panicked at library/core/src/panicking.rs:126:5:
panic in a function that cannot unwind
stack backtrace:
   0:     0x562b11e2b2fc - std::backtrace_rs::backtrace::libunwind::trace::hcccbe357f6294ee4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x562b11e2b2fc - std::backtrace_rs::backtrace::trace_unsynchronized::h2aeedc764cf5993d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x562b11e2b2fc - std::sys_common::backtrace::_print_fmt::h5253f13953735ceb
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x562b11e2b2fc - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h10e03889795ce36f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x562b11e4aecc - core::fmt::rt::Argument::fmt::hb786e11d88f815da
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/rt.rs:138:9
   5:     0x562b11e4aecc - core::fmt::write::h8196208c7c3ea798
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/fmt/mod.rs:1094:21
   6:     0x562b11e28fce - std::io::Write::write_fmt::hdd2d932fce82b22e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/io/mod.rs:1714:15
   7:     0x562b11e2b0e4 - std::sys_common::backtrace::_print::hee67efbbcef8ebe2
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x562b11e2b0e4 - std::sys_common::backtrace::print::h1f9d56503b146d30
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x562b11e2c87a - std::panicking::panic_hook_with_disk_dump::{{closure}}::h863c0efb88e46827
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:278:22
  10:     0x562b11e2c567 - std::panicking::panic_hook_with_disk_dump::h7a9bb486f3291dc7
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:312:9
  11:     0x562b11e2ce7b - std::panicking::default_hook::h7e8caec6028d8d9d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:239:5
  12:     0x562b11e2ce7b - std::panicking::rust_panic_with_hook::h83c27eadec9ef70a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:729:13
  13:     0x562b11e2cd31 - std::panicking::begin_panic_handler::{{closure}}::hd577ca9f8724d099
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:619:13
  14:     0x562b11e2b826 - std::sys_common::backtrace::__rust_end_short_backtrace::h5a1a2830cb802d5e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:170:18
  15:     0x562b11e2cac2 - rust_begin_unwind
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:617:5
  16:     0x562b11e0ee73 - core::panicking::panic_nounwind_fmt::h612fcdcf4aa7da1e
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:96:14
  17:     0x562b11e0ef17 - core::panicking::panic_nounwind::h4dbadcdcb4ff29ed
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:126:5
  18:     0x562b11e0efa3 - core::panicking::panic_cannot_unwind::had39ece280b9c200
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/panicking.rs:189:5
  19:     0x562b11e0f78a - playground::main::h3a7c7f175b3be352
                               at /playground/src/main.rs:9:1
  20:     0x562b11e0f6bb - core::ops::function::FnOnce::call_once::hacc5d76449aef962
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:250:5
  21:     0x562b11e0f50e - std::sys_common::backtrace::__rust_begin_short_backtrace::h8e74152d9bd2457f
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/sys_common/backtrace.rs:154:18
  22:     0x562b11e0f581 - std::rt::lang_start::{{closure}}::h3d7d79b4aed530fe
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:166:18
  23:     0x562b11e26b7b - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hadefdea4fbcf6398
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/core/src/ops/function.rs:284:13
  24:     0x562b11e26b7b - std::panicking::try::do_call::haa16a0bcad25b40d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  25:     0x562b11e26b7b - std::panicking::try::h9367aba29c754779
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  26:     0x562b11e26b7b - std::panic::catch_unwind::h4021f90141f42c42
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  27:     0x562b11e26b7b - std::rt::lang_start_internal::{{closure}}::hff568c1c1264e3e9
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:48
  28:     0x562b11e26b7b - std::panicking::try::do_call::ha9e4f3477463e2d1
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:524:40
  29:     0x562b11e26b7b - std::panicking::try::hac29284aba256fb6
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panicking.rs:488:19
  30:     0x562b11e26b7b - std::panic::catch_unwind::h985169b2a86bf7f4
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/panic.rs:142:14
  31:     0x562b11e26b7b - std::rt::lang_start_internal::h23bd64986d4ee27a
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:148:20
  32:     0x562b11e0f55a - std::rt::lang_start::hc617a4fa67be1c4d
                               at /rustc/6ef7d16be0fb9d6ecf300c27990f4bff49d22d46/library/std/src/rt.rs:165:17
  33:     0x562b11e0f7be - main
  34:     0x7f7403a7e083 - __libc_start_main
  35:     0x562b11e0f43e - _start
  36:                0x0 - <unknown>
thread caused non-unwinding panic. aborting.

Having 2 stacktraces is already somewhat strange. And doesn't the panic machinery know that a panic-while-panicking occurred, so that it can print that?

Amanieu

Amanieu commented on Aug 20, 2023

@Amanieu
Member

That's a drop called from normal execution, not from a landing pad. I was specifically referring to a drop called from an unwind landing pad that is already being invoked as part of a previous unwind.

Having 2 stacktraces is already somewhat strange. And doesn't the panic machinery know that a panic-while-panicking occurred, so that it can print that?

The panic machinery can't determine that on its own, because this code is perfectly valid and shouldn't abort at the point of the inner panic, it should continue unwinding normally:

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");
RalfJung

RalfJung commented on Aug 20, 2023

@RalfJung
Member

Hm, I guess what happens is that the drop calls on the unwind path have UnwindAction::Terminate -- it's no longer the panic machinery that detects double-panic, it's the structure of the code itself. (EDIT: that's what you also just posted concurrently. :)

So to fix that we'd probably need some sort of reason field on UnwindAction::Terminate that records whether this is terminate-due-to-unwind-in-drop-on-cleanup-path or terminate-due-to-unwind-that-would-leave-extern "C".

RalfJung

RalfJung commented on Aug 20, 2023

@RalfJung
Member

And then the 2nd backtrace occurs because panic_cannot_unwind is the third panic in this program, and it runs into

// If this is a double panic, make sure that we print a backtrace
// for this panic. Otherwise only print it if logging is enabled.
let backtrace = if panic_count::get_count() >= 2 {
BacktraceStyle::full()
} else {
crate::panic::get_backtrace_style()
};

That's probably also undesirable for this case.

Amanieu

Amanieu commented on Aug 20, 2023

@Amanieu
Member

There is some value in having a backtrace here since it shows you which function on the stack was no-unwind. But I agree that in practice this has rather limited value.

27 remaining items

Loading
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

    A-panicArea: Panicking machineryC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @Amanieu@RalfJung@SUPERCILEX@bjorn3@asquared31415

      Issue actions

        Very confusing error message when panicking during a panic · Issue #114954 · rust-lang/rust