rust-lang / rust-lang/rust

Using thread::sleep inside panic hook aborts panic hook

Open
#124,965 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-panic C-bug O-windows T-libs
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.