authorgravatar for ben@magicmoremagic.comBen Crist <ben@magicmoremagic.com> 2022-11-20 17:41:33-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-17 16:56:39-07:00
logfb9376bd0499e2124616da1aeed7fe4e8bdd4f52
tree7c6bd3ce0d0fabdfeaf1968e99f7bba3a02fe176
parent6d47198303847409a900f57bbe84195b32375093

Double check that child processes have really exited when

TerminateProcess reports ACCESS_DENIED

1 files changed, 9 insertions(+), 1 deletions(-)

lib/std/child_process.zig+9-1
......@@ -222,7 +222,15 @@ pub const ChildProcess = struct {
222222 }
223223
224224 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 },
226234 else => return err,
227235 };
228236 try self.waitUnwrappedWindows();