From fb9376bd0499e2124616da1aeed7fe4e8bdd4f52 Mon Sep 17 00:00:00 2001 From: Ben Crist Date: Sun, 20 Nov 2022 17:41:33 -0600 Subject: [PATCH] Double check that child processes have really exited when TerminateProcess reports ACCESS_DENIED --- lib/std/child_process.zig | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/std/child_process.zig b/lib/std/child_process.zig index 645cb841e4..f8cb1be221 100644 --- a/lib/std/child_process.zig +++ b/lib/std/child_process.zig @@ -222,7 +222,15 @@ pub const ChildProcess = struct { } windows.TerminateProcess(self.id, exit_code) catch |err| switch (err) { - error.PermissionDenied => return error.AlreadyTerminated, + error.PermissionDenied => { + // Usually when TerminateProcess triggers a ACCESS_DENIED error, it + // indicates that the process has already exited, but there may be + // some rare edge cases where our process handle no longer has the + // PROCESS_TERMINATE access right, so let's do another check to make + // sure the process is really no longer running: + windows.WaitForSingleObjectEx(self.handle, 0, false) catch return err; + return error.AlreadyTerminated; + }, else => return err, }; try self.waitUnwrappedWindows();