Using thread::sleep inside panic hook aborts panic hook
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code:
panic::set_hook(Box::new(|panic_info| {
log::debug!("step 1");
thread::sleep(time::Duration::from_secs(3));
log::debug!("step 2");
if let Err(e) = Command::new("...").spawn() {
log::error!(e);
}
log::debug!("step 3");
process::exit(0);
}));
I expected to see this happen: all the code in the panic handler is executed.
Instead, this happened: with the thread::sleep, the execution of the panic handler is silently stopped at this step (the following code is simply ignored!). When removing the thread::sleep, the panic handler gets executed as expected.
Meta
cargo 1.77.2 (e52e36006 2024-03-26)
release: 1.77.2
commit-hash: e52e360061cacbbeac79f7f1215a7a90b6f08442
commit-date: 2024-03-26
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.2 vendored)
libcurl: 8.5.0-DEV (sys:0.4.70+curl-8.5.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Debian 12.0.0 [64-bit]
cargo build --target x86_64-pc-windows-gnu
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided panic hook on the stated Debian and x86_64-pc-windows-gnu environments, comparing execution with and without thread::sleep. Trace the panic-hook and process-exit behavior to determine whether the interruption is expected; done means the behavior is explained and, if it is a bug, covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100