Skip to content

Commit

Permalink
backend/kqueue: do not hang forever watching process that already exited
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Nov 6, 2023
1 parent 1b46c2d commit 59e337c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/backend/kqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ pub const Loop = struct {
// completion. We get the syscall errorcode from data and
// store it.
if (ev.flags & os.system.EV_ERROR != 0) {
c.result = c.syscall_result(@as(i32, @intCast(ev.data)));

// We reset the state so that we know that it never
// registered with kevent.
c.flags.state = .adding;
c.result = c.syscall_result(-@as(i32, @intCast(ev.data)));
} else {
// No error, means that this completion is ready to work.
c.result = c.perform(&ev);
Expand Down Expand Up @@ -1375,6 +1371,7 @@ pub const Completion = struct {
.proc = switch (errno) {
.SUCCESS => @intCast(r),
.CANCELED => error.Canceled,
.SRCH => ProcError.NoSuchProcess,
else => |err| os.unexpectedErrno(err),
},
},
Expand Down Expand Up @@ -1600,6 +1597,7 @@ pub const ProcError = os.KEventError || error{
Canceled,
MissingKevent,
Unexpected,
NoSuchProcess,
};

pub const ShutdownError = os.ShutdownError || error{
Expand Down
9 changes: 2 additions & 7 deletions src/watcher/process.zig
Original file line number Diff line number Diff line change
Expand Up @@ -313,12 +313,7 @@ fn ProcessIocp(comptime xev: type) type {
else => return .rearm,
};

return @call(.always_inline, cb, .{
common.userdataValue(Userdata, ud),
l_inner,
c_inner,
result_inner
});
return @call(.always_inline, cb, .{ common.userdataValue(Userdata, ud), l_inner, c_inner, result_inner });
},
}
} else |err| {
Expand Down Expand Up @@ -438,7 +433,7 @@ fn ProcessTests(
_: *xev.Completion,
r: Impl.WaitError!u32,
) xev.CallbackAction {
ud.?.* = r catch unreachable;
ud.?.* = r catch 0;
return .disarm;
}
}).callback);
Expand Down

0 comments on commit 59e337c

Please sign in to comment.