Skip to content

Commit ba869da

Browse files
authored
Rollup merge of #87185 - waterlens:issue-86499-fix, r=Mark-Simulacrum
Fix panics on Windows when the build was cancelled Fixes #86499 cc `@jyn514`
2 parents f335bca + 3c384ce commit ba869da

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/bootstrap/job.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,20 @@ pub unsafe fn setup(build: &mut Build) {
103103
};
104104

105105
let parent = OpenProcess(PROCESS_DUP_HANDLE, FALSE, pid.parse().unwrap());
106-
assert!(
107-
!parent.is_null(),
108-
"PID `{}` doesn't seem to exist: {}",
109-
pid,
110-
io::Error::last_os_error()
111-
);
106+
107+
// If we get a null parent pointer here, it is possible that either
108+
// we have got an invalid pid or the parent process has been closed.
109+
// Since the first case rarely happens
110+
// (only when wrongly setting the environmental variable),
111+
// so it might be better to improve the experience of the second case
112+
// when users have interrupted the parent process and we don't finish
113+
// duplicating the handle yet.
114+
// We just need close the job object if that occurs.
115+
if parent.is_null() {
116+
CloseHandle(job);
117+
return;
118+
}
119+
112120
let mut parent_handle = ptr::null_mut();
113121
let r = DuplicateHandle(
114122
GetCurrentProcess(),

0 commit comments

Comments
 (0)