Detegr / rust-ctrlc

Easy Ctrl-C handler for Rust projects
https://crates.io/crates/ctrlc
Other
599 stars 79 forks source link

Ctrl+C is awkward with Windows #61

Closed ghost closed 4 years ago

ghost commented 4 years ago

With Zola for example it says:

Press Ctrl+C to stop

but if you press that, it doesnt stop. You have to press it 3 times, or hold it. Then it does this:

Encountered an error: other os error
Enable a logger to see more information.
Detegr commented 4 years ago

Are you using cmd.exe or powershell? Is the example of this repository working on your machine?

ghost commented 4 years ago

@Detegr actually readme_example works fine

Detegr commented 4 years ago

In that case the issue is in how Zola handles the signal, I think.

Keats commented 4 years ago

Any idea what we are doing wrong in https://github.com/getzola/zola/blob/master/src/cmd/serve.rs#L282-L286 ? I'll print the remove error message in case it's related but that seems unlikely

Detegr commented 4 years ago

I would probably modify the handler to change an AtomicBool which would be checked in the loop (in addition to rx.recv()), and handle the cleanup outside of the signal handler. However, I don't see why your current solution would not work. Only thing that comes across my mind is that Windows likes to lock directories and files that are in use, and refuse to delete them. But then again, you throw the Result of remove_dir_all away, so that should not matter. Have you tried for example adding a debug print to the handler and see whether it gets called properly?