diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2021-07-24 04:31:05 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-24 04:31:05 +0900 |
| commit | ba869da8891627c78ef0f328d737e971c36da89e (patch) | |
| tree | 508953fcaa861eca2d42093d8231e1228054b156 | |
| parent | f335bca8a5a8d754cbe3832e80b40165cd7ec6e3 (diff) | |
| parent | 3c384cee52e002244caaa0ef0288aadcb85be691 (diff) | |
| download | rust-ba869da8891627c78ef0f328d737e971c36da89e.tar.gz rust-ba869da8891627c78ef0f328d737e971c36da89e.zip | |
Rollup merge of #87185 - waterlens:issue-86499-fix, r=Mark-Simulacrum
Fix panics on Windows when the build was cancelled Fixes #86499 cc `@jyn514`
| -rw-r--r-- | src/bootstrap/job.rs | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/bootstrap/job.rs b/src/bootstrap/job.rs index 2fe9b06e426..5c0322e18a4 100644 --- a/src/bootstrap/job.rs +++ b/src/bootstrap/job.rs @@ -103,12 +103,20 @@ pub unsafe fn setup(build: &mut Build) { }; let parent = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid.parse().unwrap()); - assert!( - !parent.is_null(), - "PID `{}` doesn't seem to exist: {}", - pid, - io::Error::last_os_error() - ); + + // If we get a null parent pointer here, it is possible that either + // we have got an invalid pid or the parent process has been closed. + // Since the first case rarely happens + // (only when wrongly setting the environmental variable), + // so it might be better to improve the experience of the second case + // when users have interrupted the parent process and we don't finish + // duplicating the handle yet. + // We just need close the job object if that occurs. + if parent.is_null() { + CloseHandle(job); + return; + } + let mut parent_handle = ptr::null_mut(); let r = DuplicateHandle( GetCurrentProcess(), |
