Skip to content

Commit

Permalink
termio/exec: call waitpid in process exit callback
Browse files Browse the repository at this point in the history
Fixes #4554

When a process exited on its own (we didn't kill it), we were not
calling waitpid. This commit adds a waitpid call in the event loop
process exit notification.

This happened because when an external exit happened we could call
`subprocess.externalExit` which tells our subprocess manager to NOT kill
the process (since its already dead). Unfortunately in this case it
means we also didn't call waitpid.
  • Loading branch information
mitchellh committed Jan 24, 2025
1 parent 69dcea5 commit 2b3d008
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/termio/Exec.zig
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ fn processExit(
const execdata = &td.backend.exec;
execdata.exited = true;

// The process exited but kqueue/epoll/io_uring don't reap
// the process so we have to call waitpid here. Since we're sure
// the process has exited (this callback is called) we call it
// without any WNOHANG or anything.
if (comptime builtin.os.tag != .windows) {
const result = std.posix.waitpid(execdata.process.pid, 0);
log.debug("child process exited. waitpid result={}", .{result});
}

// Determine how long the process was running for.
const runtime_ms: ?u64 = runtime: {
const process_end = std.time.Instant.now() catch break :runtime null;
Expand Down

0 comments on commit 2b3d008

Please sign in to comment.