Repository navigation
Fix interaction between timeouts and cancelation of spawned tasks - #181
Conversation
📝 WalkthroughWalkthroughRefactors timer handling and cancellation semantics: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🧰 Additional context used📓 Path-based instructions (1)**/*.zig📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧠 Learnings (4)📚 Learning: 2025-11-04T10:29:56.949ZApplied to files:
📚 Learning: 2025-10-10T05:59:17.087ZApplied to files:
📚 Learning: 2025-10-15T19:38:44.659ZApplied to files:
📚 Learning: 2025-10-03T11:09:46.846ZApplied to files:
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (1)
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: 1
🤖 Fix all issues with AI agents
In @src/runtime/timeout.zig:
- Around line 260-293: The test "Timeout: cancels spawned task via join" is
calling Timeout.set with a raw 10 which is interpreted as 10 nanoseconds; change
the call to pass 10 milliseconds by multiplying 10 by the
nanoseconds-per-millisecond constant (use std.time.ns_per_ms) so that
Timeout.set(rt, ...) receives the timeout in nanoseconds as expected; update the
call to Timeout.set in the Test.main to use 10 * std.time.ns_per_ms (i.e.,
convert ms to ns) to avoid flakiness.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/ev/loop.zigsrc/runtime/timeout.zigsrc/select.zig
🧰 Additional context used
📓 Path-based instructions (1)
**/*.zig
📄 CodeRabbit inference engine (CLAUDE.md)
Use
zig envto get the path to the Zig standard library when checking standard library
Files:
src/select.zigsrc/runtime/timeout.zigsrc/ev/loop.zig
🧠 Learnings (4)
📚 Learning: 2025-10-23T16:17:53.575Z
Learnt from: lalinsky
Repo: lalinsky/zio PR: 70
File: src/select.zig:145-153
Timestamp: 2025-10-23T16:17:53.575Z
Learning: In src/select.zig, the select() function is designed to accept futures either as copyable wrappers (e.g., JoinHandle(T)) by value, or as pointers (e.g., &reset_event) for value-owned types. This is intentional, and users are expected to pass the appropriate form based on the future type.
Applied to files:
src/select.zig
📚 Learning: 2025-10-16T14:33:19.718Z
Learnt from: lalinsky
Repo: lalinsky/zio PR: 48
File: src/core/ConcurrentAwaitableList.zig:254-269
Timestamp: 2025-10-16T14:33:19.718Z
Learning: In the zio repository's `src/core/ConcurrentAwaitableList.zig` and `src/core/Awaitable.zig`, the `in_list` field should remain debug-only (conditional compilation with `builtin.mode == .Debug`). Double-removal detection in `ConcurrentAwaitableList.remove()` uses pointer-based checks (comparing `prev`/`next` against `head`/`tail`) rather than relying on a regular `in_list` field.
Applied to files:
src/select.zig
📚 Learning: 2025-10-10T05:59:17.087Z
Learnt from: lalinsky
Repo: lalinsky/zio PR: 41
File: src/udp.zig:79-82
Timestamp: 2025-10-10T05:59:17.087Z
Learning: In UDP socket operations (src/udp.zig), error.Canceled from result_data.result represents OS/IO-level cancellation (e.g., io_uring), not user-requested cancellation. User cancellation is handled by waitForXevCompletion() via try. OS-level error.Canceled should be mapped to error.Unexpected as it represents an unexpected system event.
Applied to files:
src/select.zigsrc/runtime/timeout.zig
📚 Learning: 2025-10-03T11:09:46.846Z
Learnt from: lalinsky
Repo: lalinsky/zio PR: 18
File: src/net.zig:18-25
Timestamp: 2025-10-03T11:09:46.846Z
Learning: In zio's `Runtime.BlockingTask`, calling `deinit()` on a blocking task only frees the task wrapper (TaskData) itself, not the result returned by the blocking function. The result remains valid and owned by the caller, who is responsible for its cleanup. This is the intended design for async blocking tasks.
Applied to files:
src/runtime/timeout.zig
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: cubic · AI code reviewer
- GitHub Check: test (windows-latest)
🔇 Additional comments (4)
src/select.zig (1)
462-465: LGTM! Correct state reset for cancellation retry.The state swap from
.readyto.preparing_to_waitis necessary becausefut.cancel()wakes the task (setting state to.ready), but the nextyielditeration expects.preparing_to_waitfor its CAS to succeed. The assertion verifies this state transition.src/ev/loop.zig (3)
499-502: Clean refactoring - struct encapsulates timer check results.The
TimerCheckResultstruct groups the timeout value with a flag indicating whether timers fired, making the return value more expressive than a bare optional.
504-516: Improved timer handling - tracks fired state correctly.The refactored
checkTimersnow returns both the next timeout and whether any timers fired during this check. Thefiredflag is properly set when timers are completed (line 514) and preserved across the loop, allowing callers to differentiate between "no timers" and "timers just fired."
635-642: Better responsiveness - avoids blocking after timer fires.Using
timer_result.firedin the timeout calculation (line 640) prevents the loop from blocking immediately after processing timers. This ensures that any work triggered by timer callbacks gets a chance to run without an unnecessary wait cycle.
No description provided.