Detegr/rust-ctrlc

Handler code does not finish

Closed this issue · 2 comments

Trying to use the crate I manage to set a handler with some clean up code. When a signal is caught, the handler is indeed executed, but it's killed half way before it can finish (no panic or untreated errors are being generated in the handler function). The behavior occurs with both cargo run and through systemctl commands. Any ideas why this is happening?
The code looks like this:

fn set_termination_handler() {
    let running = Arc::new(AtomicBool::new(true));
    let r = running.clone();
    ctrlc::set_handler(move || {
        info!("Termination signal received - Cleaning up");
        clean_up();
        r.store(false, Ordering::SeqCst);
    }).expect("Error setting Termination handler");
}

Now, I dont actually have a necessity for the atomic since I'm not checking the condition in a busy loop, instead I'm blocking my future (Actix web server) with await after setting the handler.
As I said, the handler is indeed called, but it never finish the execution of its instructions. Any ideas?

I would guess actix does something funky here. I am not sure how well this crate works in async context. If you can provide a full example with actix in it, I can try to figure out what is going on.

Detegr commented

Closed as stale.