rust-ctor icon indicating copy to clipboard operation
rust-ctor copied to clipboard

4 tests combined with `catch_unwind` under `#[dtor]`, result in illegal instruction

Open da-x opened this issue 3 years ago • 5 comments

Currently with latest - ctor v0.1.21. this reproduces quite reliably.

#[test] fn a() {}
#[test] fn b() {}
#[test] fn c() {}
#[test] fn d() {}

#[ctor::dtor]
fn after_all() {
    let _ = std::panic::catch_unwind(|| {
        panic!("Testing catch unwind");
    });
}

cargo test execution, results in:

thread panicked while processing panic. aborting.
error: test failed, to rerun pass '--bin x'

Caused by:
  process didn't exit successfully: `/home/dan/trash/x/target/debug/deps/x-63d0f56f1617b059` (signal: 4, SIGILL: illegal instruction)

da-x avatar Oct 10 '21 18:10 da-x

The expected result is that the panic is caught and that the program doesn't crash. Is it related to known limitations?

da-x avatar Oct 10 '21 18:10 da-x

Interesting. This is a novel bug. Does cargo test -j1 make it work? Perhaps related to how the stdlib shuts down in the face of threading?

Generally use of std in ctor or dtor is not guaranteed to work but it would be good to understand what's happening here.

mmastrac avatar Oct 11 '21 18:10 mmastrac

Happens with -j 1 too.

da-x avatar Oct 11 '21 18:10 da-x

Found something interesting -

Building and testing for a musl target works as expected, tested with --target=x86_64-unknown-linux-musl.

So this has something to do with glibc perhaps. I'm using Fedora Linux, glibc package: glibc-2.32-10.fc33.x86_64.

da-x avatar Oct 11 '21 18:10 da-x

FWIW, I just tested this on my Mac (Big Sur 11.5.2 - not sure how to get the glibc version) laptop and it appears to behave as expected.

  • With your same code, it panics with your message
  • Replacing panic! with a simple println! prints out the message; I still see the original panics from a failed test.

I found this interesting because I use ctor to setup test data in a directory, and then wanted to use dtor to clean up on a successful run of all tests, but leave the contents if any of the tests failed for further troubleshooting.

curtisforrester avatar Jan 27 '22 16:01 curtisforrester

I suspect that this is fixed now with the latest __cxa_atexit code in 0.1.25. Please feel free to reopen.

mmastrac avatar Oct 18 '22 21:10 mmastrac