| ... | @@ -222,7 +222,15 @@ pub const ChildProcess = struct { | ... | @@ -222,7 +222,15 @@ pub const ChildProcess = struct { |
| 222 | } | 222 | } |
| 223 | | 223 | |
| 224 | windows.TerminateProcess(self.id, exit_code) catch |err| switch (err) { | 224 | windows.TerminateProcess(self.id, exit_code) catch |err| switch (err) { |
| 225 | error.PermissionDenied => return error.AlreadyTerminated, | 225 | error.PermissionDenied => { |
| | 226 | // Usually when TerminateProcess triggers a ACCESS_DENIED error, it |
| | 227 | // indicates that the process has already exited, but there may be |
| | 228 | // some rare edge cases where our process handle no longer has the |
| | 229 | // PROCESS_TERMINATE access right, so let's do another check to make |
| | 230 | // sure the process is really no longer running: |
| | 231 | windows.WaitForSingleObjectEx(self.handle, 0, false) catch return err; |
| | 232 | return error.AlreadyTerminated; |
| | 233 | }, |
| 226 | else => return err, | 234 | else => return err, |
| 227 | }; | 235 | }; |
| 228 | try self.waitUnwrappedWindows(); | 236 | try self.waitUnwrappedWindows(); |