Skip to content

Use individual xev.Completion per timeout - #121

Merged
lalinsky merged 1 commit into
mainfrom
timeout-clear
Nov 3, 2025
Merged

lalinsky merged 1 commit into
mainfrom
timeout-clear

Conversation

@lalinsky

@lalinsky lalinsky commented Nov 3, 2025

Copy link
Copy Markdown
Owner

The experiment with using a single xev.Completion for all timeouts was not working, it's hard to keep them updated.

By using a separate xev.Completion per timeout, we move the responsibility to libxev.

This way, we can properly wait for the timeout to complete.

The experiment with using a single xev.Completion for all timeouts
was not working, it's hard to keep them updated.

By using a separate xev.Completion per timeout, we move the
responsibility to libxev.

This way, we can properly wait for the timeout to complete.
@coderabbitai

coderabbitai Bot commented Nov 3, 2025 •

Copy link
Copy Markdown
Contributor

Walkthrough

Refactored timeout handling from a centralized heap-based system to distributed per-Timeout timers. Removed shared timer fields from AnyTask and migrated timer/completion state into individual Timeout instances, replacing callback-driven timeout management with explicit timer-triggered task resumption.

Changes

Cohort / File(s) Summary
Task structure simplification
src/core/task.zig
Removed timer_c, timer_cancel_c, and timeouts fields from AnyTask; removed TimeoutHeap import. Added setTimeout(self) bool method with CAS-based atomic status updates. Removed timer callback functions (timeoutCallback, noopTimerCancelCallback). Updated checkTimeout logic to prioritize user cancellation over timeout-triggered cancellation.
Timeout timer independence
src/core/timeout.zig
Replaced heap/deadline fields with per-Timeout timer, timer_c, timer_cancel_c, and triggered fields. Rewrote Timeout.set to initialize per-Timeout timers with dedicated callback. Rewrote Timeout.clear to cancel and await timer completion via cancellation path. Added timeoutCallback and cancelCallback for timer event handling and task resumption.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • The atomic CAS loop in setTimeout and its interaction with timeout-triggered vs. user cancellation needs careful verification
  • Timer callback semantics and task resumption ordering in timeoutCallback — ensure triggered state is set correctly before task resume
  • Timeout.clear cancellation path and waitForIo interaction; verify proper cleanup and no dangling references
  • checkTimeout priority logic between user cancellation and timeout-triggered decrement
  • Cross-struct coupling between AnyTask and Timeout — verify no race conditions in task reference management

Possibly related PRs

Poem

⏲️ Timers once shared in a heap so crowded,
Now scatter independent, self-counted,
Each timeout spins its own wheel,
Racing to wake its task's heel,
No more global contention, just callback and feel.

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main architectural change: moving from shared timeout completion handling to individual xev.Completion per timeout, which aligns with the changeset.
Description check ✅ Passed The description explains the rationale behind the change: a previous single xev.Completion approach wasn't working and was hard to maintain, now delegating to libxev with per-timeout completions.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch timeout-clear

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/core/task.zig (1)

81-87: Docstring no longer matches what the code does.

This helper now just updates canceled_status and returns a bool so the caller can decide whether to flag the timeout. Please refresh the comment so future readers aren't chasing an outdated description.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c589374 and b78cecd.

📒 Files selected for processing (2)
  • src/core/task.zig (1 hunks)
  • src/core/timeout.zig (1 hunks)

Comment thread src/core/timeout.zig Resolved
@lalinsky
lalinsky merged commit b2671ff into main Nov 3, 2025
@lalinsky
lalinsky deleted the timeout-clear branch November 3, 2025 21:57
@coderabbitai coderabbitai Bot mentioned this pull request Nov 12, 2025
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant