Repository navigation
Fix wait_node double-list bug in sync primitives - #182
Conversation
When a task waits on a sync primitive, its wait_node is added to the primitive's queue. If the task is cancelled or times out, the runtime tries to schedule the task by pushing its wait_node to the ready queue, but it's still in the sync primitive's queue - causing an assertion failure (node can't be in two lists at once). Fix by introducing a stack-allocated Waiter struct that wraps a separate WaitNode for sync primitive queues. The Waiter's wait_node goes into the sync primitive's queue, while the task's own wait_node remains free for runtime scheduling. Also change in_list debug checks from builtin.mode == .Debug to std.debug.runtime_safety for coverage in ReleaseSafe builds.
📝 WalkthroughWalkthroughThe PR refactors synchronization primitives to use per-operation Waiters, migrates debug safety checks from compile-time build modes to runtime safety flags, adds debug assertions in task scheduling, and introduces a custom test runner with enhanced logging and diagnostics. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 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)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (17)
🧰 Additional context used🧠 Learnings (11)📓 Common learnings📚 Learning: 2025-10-21T10:00:56.962ZApplied to files:
📚 Learning: 2025-10-16T14:33:19.718ZApplied to files:
📚 Learning: 2026-01-07T13:15:48.677ZApplied to files:
📚 Learning: 2025-10-15T19:38:44.659ZApplied to files:
📚 Learning: 2025-11-04T10:29:56.949ZApplied to files:
📚 Learning: 2025-10-03T11:09:46.846ZApplied to files:
📚 Learning: 2026-01-08T09:59:37.757ZApplied to files:
📚 Learning: 2025-10-21T10:07:03.593ZApplied to files:
📚 Learning: 2025-10-23T16:17:53.575ZApplied to files:
📚 Learning: 2025-10-10T05:59:17.087ZApplied 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 (33)
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 |
Summary
Waiterstruct that separates operation wait nodes from task wait nodesin_listdebug checks to usestd.debug.runtime_safetyfor coverage in ReleaseSafe buildsProblem
When a task waits on a sync primitive (Mutex, Condition, ResetEvent, etc.), its
wait_nodeis added to the primitive's queue. If the task is cancelled or times out, the runtime tries to schedule the task by pushing itswait_nodeto the ready queue - but it's still in the sync primitive's queue, causing an assertion failure.Solution
Introduce a
Waiterstruct insrc/sync/common.zigthat wraps a separateWaitNode. The Waiter's wait_node goes into the sync primitive's queue, while the task's own wait_node remains free for runtime scheduling.Files Changed
src/sync/common.zig(NEW) - Waiter struct definitionsrc/sync/Condition.zig- Use Waiter in wait/timedWaitsrc/sync/ResetEvent.zig- Use Waiter in wait/timedWaitsrc/sync/Notify.zig- Use Waiter in wait/timedWaitsrc/sync/Mutex.zig- Use Waiter in locksrc/sync/channel.zig- Use Waiter in send/receivesrc/sync/broadcast_channel.zig- Use Waiter in receivesrc/signal.zig- Use Waiter in wait/timedWaitstd.debug.runtime_safetyTest plan
ResetEvent: cancel waiting task