rust-ctor
rust-ctor copied to clipboard
4 tests combined with `catch_unwind` under `#[dtor]`, result in illegal instruction
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)
The expected result is that the panic is caught and that the program doesn't crash. Is it related to known limitations?
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.
Happens with -j 1
too.
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
.
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 simpleprintln!
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.
I suspect that this is fixed now with the latest __cxa_atexit code in 0.1.25. Please feel free to reopen.