Skip to content

Fix completion leak in epoll cancel path when removeFromPollQueue fails - #229

Merged
lalinsky merged 1 commit into
mainfrom
fix-epoll-cancel-completion-leak
Jan 22, 2026
Merged

lalinsky merged 1 commit into
mainfrom
fix-epoll-cancel-completion-leak

Conversation

@lalinsky

Copy link
Copy Markdown
Owner

Summary

  • Fixes a bug where completions could get stuck in .running state forever when removeFromPollQueue failed during cancellation
  • removeFromPollQueue now always cleans up the poll_queue entry when the completion list is empty, even if epoll_ctl fails (prevents stale entries)
  • cancel now always completes the target with error.Canceled regardless of removal success

Test plan

  • All existing cancel tests pass (38/38)
  • Full test suite passes (308/308)
  • Examples and benchmarks build

Fixes #212

When removeFromPollQueue fails after removing the completion from the
linked list, the cancel function would return early without completing
the target. This left the completion stuck in running state forever.

Changes:
- removeFromPollQueue now always cleans up poll_queue entry when the
  completion list is empty, even if epoll_ctl fails
- cancel now always completes the target with error.Canceled

Fixes #212
@coderabbitai

coderabbitai Bot commented Jan 22, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The epoll backend's cancellation flow is refactored to guarantee completion delivery. When removing entries from poll queues fails, the code now always delivers error.Canceled to the target completion, preventing the waiter from hanging indefinitely. This addresses a correctness issue where prior error returns left completions in .running state.

Changes

Cohort / File(s) Summary
Epoll cancellation safety
src/ev/backends/epoll.zig
removeFromPollQueue: Refactored to compute errno once, assert poll_queue removal occurred, and handle epoll_ctl failures via switch statement on error codes (.SUCCESS, .NOENT permitted, others escalate). cancel: Modified to log error details but continue execution—now always completes the target with error.Canceled regardless of poll queue removal outcome, preventing completion leaks.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

No more hangups when cancel calls,
Completions finish through the walls—
Error or success, the task is done,
Async flows like morning sun ☀️

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main bug fix: preventing completion leaks in the epoll cancel path when removeFromPollQueue fails.
Description check ✅ Passed The description clearly outlines the bug, the fix approach, and test validation relevant to the changeset.
Linked Issues check ✅ Passed The changes directly address issue #212 by ensuring completions are completed with error.Canceled regardless of removeFromPollQueue success and preventing stale poll_queue entries.
Out of Scope Changes check ✅ Passed All changes in removeFromPollQueue and cancel are focused on fixing the completion leak bug identified in issue #212, with no extraneous modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-epoll-cancel-completion-leak

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.

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.

Potential completion leak in epoll backend cancel path when removeFromPollQueue fails

1 participant