Repository navigation
std.Io: implement childWait and childKill - #368
Conversation
Part of #366. Also initialize std.testing.io_instance in the test runner so tests can use std.process.spawn via std.testing.io.
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ 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)
📝 WalkthroughWalkthroughThe PR implements concrete process child wait and kill operations. Previously stubbed methods in the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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. Review rate limit: 0/1 reviews remaining, refill in 43 minutes and 47 seconds.Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (2)
src/io.zig (1)
1763-1765: Optional cleanup: redundant compile-anchor test.
process_implis already referenced bychildWaitImpl/childKillImpl, so this test block can be dropped unless you want it as explicit documentation.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/io.zig` around lines 1763 - 1765, The small test block that anchors process_impl for compilation is redundant because process_impl is already referenced by childWaitImpl and childKillImpl; remove the test block containing "test { _ = process_impl; }" to clean up the code, leaving process_impl referenced only via childWaitImpl and childKillImpl (no other code changes required).src/process.zig (1)
31-35: Consume/checkProcessWaitresult inchildKillto honor reap semantics.Right now
childKillwaits for completion but never inspectsop.getResult(). That hides wait failures and makes “reap uncancelably” harder to trust/debug.Suggested fix
pub fn childKill(child: *std.process.Child) void { sendTermSignal(child.id.?); var op = ev.ProcessWait.init(child.id.?); waitForIoUncancelable(&op.c); + _ = op.getResult() catch {}; childCleanup(child); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/process.zig` around lines 31 - 35, childKill currently calls ev.ProcessWait.init and waitForIoUncancelable but never inspects op.getResult(), which hides wait failures; update childKill to call op.getResult() after waitForIoUncancelable (or use the returned Result/!Error path) and handle errors appropriately before calling childCleanup—e.g., propagate or log the error from op.getResult() so wait failures are not ignored; ensure you still call childCleanup in success and handle the case where op.getResult() indicates a failure from ProcessWait/sendTermSignal.
🤖 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/process.zig`:
- Around line 20-24: The switch handling the error from op.getResult() currently
maps error.Canceled to error.Canceled but must map backend/IO-level
cancellations to error.Unexpected (user cancellation is already handled by
waitForIo); update the switch in the op.getResult() catch branch to return
error.Unexpected for error.Canceled (alongside other backend errors like
ProcessNotFound and SystemResources) so IO-level cancellation isn't surfaced as
a user cancel.
- Around line 73-104: These tests call POSIX binaries (/bin/true, /bin/false,
/bin/sleep) and will fail on Windows; update the tests (the test cases
"childWait: exit code 0", "childWait: exit code 1", and "childKill: terminates
process") to skip on Windows by checking std.os.tag (or equivalent) at the top
of each test and invoking std.testing.skip with a short message when running on
Windows, so the tests only run on POSIX platforms; reference the childWait and
childKill usages when making the change.
---
Nitpick comments:
In `@src/io.zig`:
- Around line 1763-1765: The small test block that anchors process_impl for
compilation is redundant because process_impl is already referenced by
childWaitImpl and childKillImpl; remove the test block containing "test { _ =
process_impl; }" to clean up the code, leaving process_impl referenced only via
childWaitImpl and childKillImpl (no other code changes required).
In `@src/process.zig`:
- Around line 31-35: childKill currently calls ev.ProcessWait.init and
waitForIoUncancelable but never inspects op.getResult(), which hides wait
failures; update childKill to call op.getResult() after waitForIoUncancelable
(or use the returned Result/!Error path) and handle errors appropriately before
calling childCleanup—e.g., propagate or log the error from op.getResult() so
wait failures are not ignored; ensure you still call childCleanup in success and
handle the case where op.getResult() indicates a failure from
ProcessWait/sendTermSignal.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 68b2114d-7bfb-4b6f-971a-7a99a60f8d3e
📒 Files selected for processing (3)
src/io.zigsrc/process.zigtest_runner.zig
| const status = op.getResult() catch |err| switch (err) { | ||
| error.ProcessNotFound => return error.Unexpected, | ||
| error.SystemResources => return error.Unexpected, | ||
| error.Canceled => return error.Canceled, | ||
| error.Unexpected => return error.Unexpected, |
There was a problem hiding this comment.
Map op.getResult().Canceled to error.Unexpected, not error.Canceled.
User cancellation is already handled by waitForIo. A canceled result from getResult() is backend/IO-level cancellation and should not be surfaced as user cancel.
Suggested fix
const status = op.getResult() catch |err| switch (err) {
error.ProcessNotFound => return error.Unexpected,
error.SystemResources => return error.Unexpected,
- error.Canceled => return error.Canceled,
+ error.Canceled => return error.Unexpected,
error.Unexpected => return error.Unexpected,
};Based on learnings: In src/udp.zig, error.Canceled from completion result data is OS/IO-level cancellation and is expected to map to error.Unexpected.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const status = op.getResult() catch |err| switch (err) { | |
| error.ProcessNotFound => return error.Unexpected, | |
| error.SystemResources => return error.Unexpected, | |
| error.Canceled => return error.Canceled, | |
| error.Unexpected => return error.Unexpected, | |
| const status = op.getResult() catch |err| switch (err) { | |
| error.ProcessNotFound => return error.Unexpected, | |
| error.SystemResources => return error.Unexpected, | |
| error.Canceled => return error.Unexpected, | |
| error.Unexpected => return error.Unexpected, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@src/process.zig` around lines 20 - 24, The switch handling the error from
op.getResult() currently maps error.Canceled to error.Canceled but must map
backend/IO-level cancellations to error.Unexpected (user cancellation is already
handled by waitForIo); update the switch in the op.getResult() catch branch to
return error.Unexpected for error.Canceled (alongside other backend errors like
ProcessNotFound and SystemResources) so IO-level cancellation isn't surfaced as
a user cancel.
Part of #366.
Summary
src/process.zigwithchildWaitandchildKillimplementations backed byev.ProcessWaitchildWaituseswaitForIofor cancellation-aware async waiting; convertsExitStatustostd.process.Child.Termand closes stdio pipeschildKillsendsSIGTERM(POSIX) /NtTerminateProcess(Windows), then reaps the process uncancelably viawaitForIoUncancelableio.zig's vtable, replacing the@panic("TODO")stubsstd.testing.io_instancein the test runner so tests can spawn processes viastd.testing.ioNotes
The io_uring backend uses
IORING_OP_WAITID(requires Linux 6.7+) and will returnerror.Unexpectedon older kernels; tests pass with the epoll backend.Test plan
./check.sh --filter "child" --backend epoll