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

Use job objects on windows for ctrl-c to work #2370

Merged
merged 1 commit into from
Feb 11, 2016

Conversation

alexcrichton
Copy link
Member

Currently it's somewhat surprising if you're using cargo and it's then ctrl-c'd.
The child processes that Cargo spawned are likely to still be running around in
the background as they're not killed as well, and this could cause output spew
or future build failures.

This situation is handled by default on Unix because ctrl-c will end up sending
a signal to the entire process group, which kills everything, but on Windows
we're not as lucky (just Cargo itself is killed). By using job objects on
Windows we can ensure that the entire tree dies instead of just the top Cargo
process.

cc #2343

@rust-highfive
Copy link

r? @wycats

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @brson

@rust-highfive rust-highfive assigned brson and unassigned wycats Feb 8, 2016
@alexcrichton alexcrichton force-pushed the windows-jobs branch 4 times, most recently from 6ce639c to 302bbba Compare February 9, 2016 05:01
@brson
Copy link
Contributor

brson commented Feb 11, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Feb 11, 2016

📌 Commit 302bbba has been approved by brson

@bors
Copy link
Contributor

bors commented Feb 11, 2016

⌛ Testing commit 302bbba with merge 7823a5b...

@bors
Copy link
Contributor

bors commented Feb 11, 2016

💔 Test failed - cargo-win-msvc-64

@alexcrichton
Copy link
Member Author

Well, at least I can rest easy at night knowing that the test is indeed working?

Looks like our bots are running Window Server 2008 R2, which does not have support for nested jobs. We also run everything inside of dojob.exe which adds everything to a job object. So from this we can infer:

  • Cargo does indeed continue to work if it can't put itself into a job object.
  • The test added does indeed fail if job objects aren't working.

I... am not entirely sure what to do here. Maybe we can detect the Windows version and disable the test if Windows is too old? Maybe we can try adding ourself to two job objects and see if it works?

It looks like AppVeyor at least is running a newer version of Windows where the test can be run, so at least we have some coverage of it.

@alexcrichton alexcrichton deleted the windows-jobs branch February 11, 2016 19:38
@alexcrichton alexcrichton restored the windows-jobs branch February 11, 2016 19:38
@alexcrichton alexcrichton reopened this Feb 11, 2016
@bors
Copy link
Contributor

bors commented Feb 11, 2016

⌛ Testing commit 302bbba with merge 5b93d5c...

@alexcrichton
Copy link
Member Author

@bors: r-

Currently it's somewhat surprising if you're using cargo and it's then ctrl-c'd.
The child processes that Cargo spawned are likely to still be running around in
the background as they're not killed as well, and this could cause output spew
or future build failures.

This situation is handled by default on Unix because ctrl-c will end up sending
a signal to the entire *process group*, which kills everything, but on Windows
we're not as lucky (just Cargo itself is killed). By using job objects on
Windows we can ensure that the entire tree dies instead of just the top Cargo
process.

cc rust-lang#2343
@alexcrichton
Copy link
Member Author

Ok, I've added a check to only enable these tests if the tests are either (a) not in a job or (b) can add themselves to a nested job. I believe this means that buildbot tests will never run these tests (as the builders are already in a job and don't support nested jobs), but appveyor will run these tests (as will runs locally).

@bors: r=brson 5ccc842

@bors
Copy link
Contributor

bors commented Feb 11, 2016

⌛ Testing commit 5ccc842 with merge 4b7f9df...

bors added a commit that referenced this pull request Feb 11, 2016
Currently it's somewhat surprising if you're using cargo and it's then ctrl-c'd.
The child processes that Cargo spawned are likely to still be running around in
the background as they're not killed as well, and this could cause output spew
or future build failures.

This situation is handled by default on Unix because ctrl-c will end up sending
a signal to the entire *process group*, which kills everything, but on Windows
we're not as lucky (just Cargo itself is killed). By using job objects on
Windows we can ensure that the entire tree dies instead of just the top Cargo
process.

cc #2343
@bors
Copy link
Contributor

bors commented Feb 11, 2016

@bors bors merged commit 5ccc842 into rust-lang:master Feb 11, 2016
@bruno-medeiros
Copy link

Cool! I was developing some IDE features that really heavily on this (invoking and killing cargo build automatically), and sometimes I'd get an error with a newer Cargo invocation, stating that it's waiting for the build subcommands to terminate (these would be lingering subcommands of a previous invocation).

I trust this will still work if the Cargo process is killed directly (programmatically), and not just when doing a Ctrl-C on the console? In other words, Cargo isn't trying to handle SIGINT or something?

@alexcrichton
Copy link
Member Author

Indeed! Although on Unix you'll have to be sure to kill the process group rather than just the Cargo process. Other than that it should work just fine on Unix/Windows both programmatically and via ctrl-c

@bruno-medeiros
Copy link

Hum, I'm just using the Java API that spawns processes... I guess I will have to test how it actually works on Linux, see if it kills the whole process group. But from what I can see from a quick look, the only thing the Java API does on Linux is send a SIGTERM to the spawned process. I dunno if that is enough to kill the child processes of Cargo.

@alexcrichton
Copy link
Member Author

Ah yeah unfortunately killing just Cargo isn't enough to kill child process on Unix, you'll have to kill the whole process group.

@bruno-medeiros
Copy link

Ok, that's good to know then. Although, it would be nicer if this functionality were built into Cargo itself. Maybe something for a PR..

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

Successfully merging this pull request may close these issues.

6 participants