Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo seems to exit prematurely when "cargo run" receives SIGINT #4397

Closed
Svedrin opened this issue Aug 11, 2017 · 6 comments
Closed

Cargo seems to exit prematurely when "cargo run" receives SIGINT #4397

Svedrin opened this issue Aug 11, 2017 · 6 comments

Comments

@Svedrin
Copy link

Svedrin commented Aug 11, 2017

If I write code that ignores SIGINT, and then send that code an interrupt by hitting ^c, cargo forwards the signal to the target process but exits prematurely:

[13:22]mz1030@mz1030-nb111:~/tmp/threadtests# cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running `target/debug/threadtests`
^C
[13:22]mz1030@mz1030-nb111:~/tmp/threadtests# Thread exiting!

If I run the target directly, ^c is correctly ignored without me being dropped back to the shell:

[13:23]mz1030@mz1030-nb111:~/tmp/threadtests# ./target/debug/threadtests 
^C^C^C^C^C^CThread exiting!
[13:23]mz1030@mz1030-nb111:~/tmp/threadtests# 

I noticed because I had written an application that takes a second or two to clean up when it receives SIGINT. My Cargo version (installed through rustup) is:

[13:25]mz1030@mz1030-nb111:~/tmp/threadtests# cargo --version
cargo 0.20.0 (a60d185c8 2017-07-13)
[13:25]mz1030@mz1030-nb111:~/tmp/threadtests# rustc --version
rustc 1.19.0 (0ade33941 2017-07-17)
@alexcrichton
Copy link
Member

Thanks for the report! This is, however, how signals work on Unix. When you hit ctrl-c the shell sends SIGINT to the process group. In the case of Cargo nothing's listening for SIGINT so everything is torn down in a nondeterministic fashion.

@Svedrin
Copy link
Author

Svedrin commented Aug 11, 2017

@alexcrichton shouldn't cargo then make the subprocess its own process group before exec()ing the target, so that cargo "just does the right thing"? From a user perspective, this behavior feels very wrong.

@alexcrichton
Copy link
Member

The cargo subprocess and all of its children are already in the same process group, so what you're seeing is actually "the right thing" in terms of intention.

The best solution here is handling rust-lang/rustup#806

@Svedrin
Copy link
Author

Svedrin commented Aug 11, 2017

@alexcrichton what does rustup have to do with it? 😕

@alexcrichton
Copy link
Member

@Svedrin did you install Rust through rustup? If so when you execute cargo you're actually executing rustup first, then Cargo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants