]> git.lizzy.rs Git - rust.git/commitdiff
Fix panics on Windows when the build was cancelled
authorwaterlens <82268070+waterlens@users.noreply.github.com>
Fri, 16 Jul 2021 09:56:51 +0000 (17:56 +0800)
committerwaterlens <82268070+waterlens@users.noreply.github.com>
Fri, 16 Jul 2021 09:56:51 +0000 (17:56 +0800)
src/bootstrap/job.rs

index 2fe9b06e42643916d84a2c59f52f34b28cae789a..5c0322e18a4ab9fff09fa2b62be5592c546aa08d 100644 (file)
@@ -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(),