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

Projects
None yet
6 participants
@alexcrichton
Copy link
Member

alexcrichton commented Feb 8, 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

@rust-highfive

This comment has been minimized.

Copy link

rust-highfive commented Feb 8, 2016

r? @wycats

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

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Feb 8, 2016

r? @brson

@rust-highfive rust-highfive assigned brson and unassigned wycats Feb 8, 2016

@alexcrichton alexcrichton force-pushed the alexcrichton:windows-jobs branch 4 times, most recently from 6ce639c to 302bbba Feb 8, 2016

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Feb 11, 2016

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 11, 2016

📌 Commit 302bbba has been approved by brson

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 11, 2016

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

bors added a commit that referenced this pull request Feb 11, 2016

Auto merge of #2370 - alexcrichton:windows-jobs, r=brson
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

This comment has been minimized.

Copy link
Contributor

bors commented Feb 11, 2016

💔 Test failed - cargo-win-msvc-64

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Feb 11, 2016

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 alexcrichton:windows-jobs branch Feb 11, 2016

@alexcrichton alexcrichton restored the alexcrichton:windows-jobs branch Feb 11, 2016

@alexcrichton alexcrichton reopened this Feb 11, 2016

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Feb 11, 2016

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

bors added a commit that referenced this pull request Feb 11, 2016

Auto merge of #2370 - alexcrichton:windows-jobs, r=brson
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
@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Feb 11, 2016

@bors: r-

Use job objects on windows for ctrl-c to work
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

@alexcrichton alexcrichton force-pushed the alexcrichton:windows-jobs branch from 302bbba to 5ccc842 Feb 11, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Feb 11, 2016

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

This comment has been minimized.

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

Auto merge of #2370 - alexcrichton:windows-jobs, r=brson
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

This comment has been minimized.

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

2 of 3 checks passed

continuous-integration/appveyor/pr Waiting for AppVeyor build to complete
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@alexcrichton alexcrichton deleted the alexcrichton:windows-jobs branch Feb 11, 2016

@bruno-medeiros

This comment has been minimized.

Copy link

bruno-medeiros commented Apr 20, 2016

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

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Apr 20, 2016

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

This comment has been minimized.

Copy link

bruno-medeiros commented Apr 20, 2016

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

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Apr 20, 2016

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

This comment has been minimized.

Copy link

bruno-medeiros commented Apr 21, 2016

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
You can’t perform that action at this time.