Repository navigation
Track both coroutine and blocking tasks in runtime registry - #81
Conversation
Previously, Runtime.tasks only tracked AnyTask (coroutine-based tasks), causing the runtime to potentially shut down while blocking tasks were still running. Changes: - Add intrusive list fields to Awaitable (next, prev, in_list) - Create AwaitableList to track Awaitable instead of AnyTask - Add blocking tasks to registry when created and remove when completed - Consolidate cleanup logic with releaseAwaitable(awaitable, done) flag - Move maybeShutdown from Executor to Runtime for better architecture - Fix shutdown bug: blocking tasks now properly trigger shutdown This ensures proper lifecycle management for all awaitable types and prevents premature runtime shutdown.
|
Caution Review failedThe pull request is closed. WalkthroughReplaces a concurrent task registry with a simpler Awaitable-based registry: adds intrusive list fields to Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (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: 2
🧹 Nitpick comments (1)
src/runtime.zig (1)
1739-1749: Thedoneflag logic works but is subtle.When
done=false, we skip both the registry removal and the shutdown check. This is used in two scenarios:
- JoinHandle drop (awaitable stays in registry until task completes)
- Deinit cleanup (pop already removed it, don't trigger shutdown)
The deinit usage (lines 1484-1486) works because
pop()already removed the awaitable, but it's not obvious from reading this function alone.Consider adding a comment:
fn releaseAwaitable(self: *Runtime, awaitable: *Awaitable, comptime done: bool) void { + // done=true: awaitable completed, remove from registry and check for shutdown + // done=false: JoinHandle drop or already removed (e.g., during deinit) if (done) { _ = self.tasks.remove(awaitable); }
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
src/core/Awaitable.zig(1 hunks)src/core/AwaitableList.zig(1 hunks)src/core/ConcurrentAwaitableList.zig(0 hunks)src/core/WaitNode.zig(0 hunks)src/runtime.zig(11 hunks)
💤 Files with no reviewable changes (2)
- src/core/WaitNode.zig
- src/core/ConcurrentAwaitableList.zig
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-16T14:33:19.718Z
Learnt from: lalinsky
PR: lalinsky/zio#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/core/Awaitable.zigsrc/core/AwaitableList.zig
🔇 Additional comments (8)
src/core/Awaitable.zig (1)
38-41: Intrusive list fields look good.The three fields (next, prev, in_list) properly support the AwaitableList registry. The debug-only
in_listfield follows the established pattern from the codebase.Based on learnings.
src/core/AwaitableList.zig (2)
4-17: Clean registry design.The state encoding is straightforward: you can only close when empty, which prevents the complexity of draining a closed registry. Using WaitQueue's sentinel states for this is clever.
19-61: Registry methods are solid.The atomic transitions in
add()andclose()properly coordinate shutdown. Makingclose()idempotent (line 40) is the right call. The behavior wherepop()transitions back toempty_openmeans the registry can accept new tasks after draining during non-shutdown scenarios.src/runtime.zig (5)
119-121: Correct cleanup for blocking tasks.Calling
releaseAwaitablewithdone=trueafter the blocking task completes properly removes it from the registry and triggers shutdown checks.
358-361: Correct: JoinHandle drop doesn't mean task completion.Using
done=falsehere is right—the awaitable stays in the registry until it actually completes execution, even if the caller drops their handle.
526-532: JoinHandle cleanup is correct.
1037-1038: Task completion properly handled.
1719-1737: Shutdown coordination is sound.The atomic
close()transition ensures only one thread initiates shutdown. The race between task completion and new spawns is handled correctly—if a spawn sneaks in before shutdown, we simply wait for that task to complete and try again.
No description provided.