Repository navigation
Add ProcessWait for async child process waiting - #339
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds a new ProcessWait operation and cross-platform process-wait handling across backends, wiring it into the loop, blocking/thread-pool, public API, OS bindings, and tests to observe child exit codes or termination signals. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/ev/backends/common.zig`:
- Around line 694-695: The current blocking waits (Windows WaitForSingleObject
with INFINITE and POSIX waitid/waitpid) prevent the Work cancellation from being
observed; change the blocking calls in the thread-pool fallback (the code paths
around WaitForSingleObject/WAIT_OBJECT_0 and the POSIX waitid/waitpid blocks
referenced) to use a finite timeout loop (e.g., short-timeout
WaitForSingleObject or repeated waitpid(..., WNOHANG) / waitid with brief
sleeps) so the loop can periodically check the Work cancellation flag and retry
on EINTR; implement a small timeout/sleep interval, re-check cancellation each
iteration, and only break when the child has actually exited or the Work is
cancelled.
In `@src/ev/backends/kqueue.zig`:
- Around line 698-719: The process_wait branch currently treats any waitpid
error as error.Unexpected; modify the waitpid error handling (around
posix.system.waitpid in the .process_wait case handling ProcessWait) to inspect
the platform errno (posix.errno) and map ECHILD to error.ProcessNotFound,
otherwise call comp.setError(error.Unexpected) as before so kqueue matches the
epoll/io_uring semantics; keep the rest of the success path that decodes status
and calls comp.setResult(.process_wait, ...) unchanged.
In `@src/os/root.zig`:
- Line 20: The public alias change made in root.zig (pub const timespec =
posix.timespec) breaks nominal typing because syscalls use
posix.system.timespec; either revert the alias to posix.system.timespec or
update all syscall signatures and callers to use os.timespec consistently.
Concretely, restore pub const timespec = posix.system.timespec in
src/os/root.zig OR update every syscall prototype and users (examples: functions
in src/os/time.zig and src/os/fs.zig that reference posix.system.timespec, and
the public APIs exported from src/time.zig) to accept os.timespec and fix all
call sites to pass the new type. Ensure the chosen approach is applied across
syscall declarations and their callers in the same patch to keep types
consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 1783b320-56b7-4a72-84ff-70d111269f0a
📒 Files selected for processing (14)
src/ev/backends/common.zigsrc/ev/backends/epoll.zigsrc/ev/backends/io_uring.zigsrc/ev/backends/iocp.zigsrc/ev/backends/kqueue.zigsrc/ev/backends/poll.zigsrc/ev/blocking.zigsrc/ev/completion.zigsrc/ev/loop.zigsrc/ev/root.zigsrc/ev/test/process_wait.zigsrc/ev/tests.zigsrc/os/root.zigsrc/os/windows.zig
Co-authored-by: Lukáš Lalinský <[email protected]>
|
@claude we need to change the IOCP backend to use callback based approach, use wine to test it |
|
Claude finished @lalinsky's task in 7m 19s —— View job Implemented callback-based IOCP process_wait
SummaryThe IOCP backend now uses a fully callback-based approach for
New
The |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/ev/backends/kqueue.zig (1)
711-718: Exit status decoding differs from epoll when process is signaled.When a process is terminated by a signal, there's no meaningful exit code. The epoll backend (from
src/ev/backends/epoll.zig:786-789) explicitly sets.code = 0in this case:.code = if (si_code == CLD_EXITED) `@intCast`(si_status) else 0,For consistent cross-platform behavior, kqueue should do the same:
Proposed fix for consistent exit status
// Decode wait status (WEXITSTATUS and WTERMSIG equivalent) const ustatus: u32 = `@bitCast`(status); const exit_code: u8 = `@intCast`((ustatus >> 8) & 0xff); const signal_num: u8 = `@intCast`(ustatus & 0x7f); comp.setResult(.process_wait, .{ - .code = exit_code, + .code = if (signal_num != 0) 0 else exit_code, .signal = if (signal_num != 0) signal_num else null, });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/ev/backends/kqueue.zig` around lines 711 - 718, The kqueue exit-status decoding currently sets .code to exit_code even when the process was signaled; change the logic in the block that computes ustatus/exit_code/signal_num and calls comp.setResult(.process_wait) so that .code is 0 when the process was terminated by a signal (i.e., when signal_num != 0) and only uses exit_code when not signaled, and preserve .signal as null when there is no signal; update the comp.setResult call (the .process_wait result construction) to mirror the epoll behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/ev/backends/kqueue.zig`:
- Around line 711-718: The kqueue exit-status decoding currently sets .code to
exit_code even when the process was signaled; change the logic in the block that
computes ustatus/exit_code/signal_num and calls comp.setResult(.process_wait) so
that .code is 0 when the process was terminated by a signal (i.e., when
signal_num != 0) and only uses exit_code when not signaled, and preserve .signal
as null when there is no signal; update the comp.setResult call (the
.process_wait result construction) to mirror the epoll behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 0b3573cf-3e9c-46ab-8f6b-d2a96d37b893
📒 Files selected for processing (1)
src/ev/backends/kqueue.zig
Use RegisterWaitForSingleObject to register a Windows thread-pool callback on the process handle. When the process exits, the callback calls PostQueuedCompletionStatus to notify the IOCP event loop, which then retrieves the exit code via GetExitCodeProcess. This avoids blocking a thread pool thread for the duration of the process lifetime, and integrates cleanly with the existing IOCP completion dispatch path. Co-authored-by: Lukáš Lalinský <[email protected]>
|
@claude the IOCP process waiter should be cancelable, can we make it so? |
|
Claude finished @lalinsky's task in 4m 56s —— View job Making IOCP process_wait cancelable
SummaryThe IOCP Changes to
|
Add cancellation support for process_wait in the IOCP backend: - Add atomic 'posted' flag to ProcessWaitData to prevent double-posting when both the callback and cancel() race to post an IOCP completion - Make processWaitCallback use CAS before posting so the cancel path can win the race if it gets there first - Handle .process_wait in cancel(): call UnregisterWaitEx with INVALID_HANDLE_VALUE to wait for any in-flight callback, then post the completion ourselves if the callback didn't already do so - In processCompletion, check cancel_state.requested and set error.Canceled instead of calling GetExitCodeProcess - Reset the posted flag in submitProcessWait to support resubmission Co-authored-by: Lukáš Lalinský <[email protected]>
Summary
Test plan