Skip to content

queue: clear next before re-enqueue - #170

Open
dacheng-gao wants to merge 1 commit into
mitchellh:mainfrom
dacheng-zig:dacheng/clear-next
Open

dacheng-gao wants to merge 1 commit into
mitchellh:mainfrom
dacheng-zig:dacheng/clear-next

Conversation

@dacheng-gao

Copy link
Copy Markdown

Probablly fixes #169

@mitchellh

Copy link
Copy Markdown
Owner

Thanks, we're definitely going to need a test to cover this. If you don't get to it I can try eventually

@dacheng-gao

Copy link
Copy Markdown
Author

ping @mitchellh

bryanjeal added a commit to bryanjeal/libxev that referenced this pull request Jun 27, 2026
…xt in submit

Bug mitchellh#209: kqueue tick(0) EV_DELETE flush
- Changed early exit condition from 'if (wait == 0) break' to
  'if (wait == 0 and changes == 0) break' so pending EV_DELETE
  kevent changes from the event-processing loop are flushed
  before tick(0) returns.

Bug mitchellh#170: rearm state correction
- When a non-kqueue completion (close, shutdown, threadpool
  fallback) returns .rearm, set flags.state to .adding before
  pushing to the submissions queue. Previously .dead state
  caused submit() to route through stop_completion (cancel)
  instead of start() (resubmit).

Issue mitchellh#169: defensive next-pointer clear in submit()
- Explicitly clear c.next before push to completions queue
  when processing kevent-returned events in submit(). This
  prevents an assertion failure if a completion is present
  in multiple queues concurrently (race condition).
endel pushed a commit to endel/libxev that referenced this pull request Sep 26, 2026
Add tests for two bugs:

Bug mitchellh#209: tick(0) EV_DELETE flush - kqueue tick(0) may leave
stale kernel filters when disarming. Six tests added covering
multiple disarms, write/read disarm on same fd, rapid cycles,
no-op tick, stale filter detection, and the kevent-event-processing
race path (fires without fix, passes with fix).

Bug mitchellh#170: rearm from non-kqueue completions - when a completion
that completes without kqueue registration returns .rearm, it
is pushed to submissions with .dead state which gets routed to
stop_completion instead of start. Integration test added (fails
without fix, passes with fix).

Queue unit tests added verifying re-enqueue across queues,
drain-and-refill, and rapid cycle invariants.

(cherry picked from commit efdf2cb)
(cherry picked from commit 6995a3a)
endel pushed a commit to endel/libxev that referenced this pull request Sep 26, 2026
…xt in submit

Bug mitchellh#209: kqueue tick(0) EV_DELETE flush
- Changed early exit condition from 'if (wait == 0) break' to
  'if (wait == 0 and changes == 0) break' so pending EV_DELETE
  kevent changes from the event-processing loop are flushed
  before tick(0) returns.

Bug mitchellh#170: rearm state correction
- When a non-kqueue completion (close, shutdown, threadpool
  fallback) returns .rearm, set flags.state to .adding before
  pushing to the submissions queue. Previously .dead state
  caused submit() to route through stop_completion (cancel)
  instead of start() (resubmit).

Issue mitchellh#169: defensive next-pointer clear in submit()
- Explicitly clear c.next before push to completions queue
  when processing kevent-returned events in submit(). This
  prevents an assertion failure if a completion is present
  in multiple queues concurrently (race condition).

(cherry picked from mitchellh#224; the .rearm arm is merged with
this fork's keep-active fix: a completion still registered with kqueue
stays .active, one never registered is resubmitted as .adding)

(cherry picked from commit a7502d6)
(cherry picked from commit 570e3b0)
endel pushed a commit to endel/libxev that referenced this pull request Sep 26, 2026
Add tests for two bugs:

Bug mitchellh#209: tick(0) EV_DELETE flush - kqueue tick(0) may leave
stale kernel filters when disarming. Six tests added covering
multiple disarms, write/read disarm on same fd, rapid cycles,
no-op tick, stale filter detection, and the kevent-event-processing
race path (fires without fix, passes with fix).

Bug mitchellh#170: rearm from non-kqueue completions - when a completion
that completes without kqueue registration returns .rearm, it
is pushed to submissions with .dead state which gets routed to
stop_completion instead of start. Integration test added (fails
without fix, passes with fix).

Queue unit tests added verifying re-enqueue across queues,
drain-and-refill, and rapid cycle invariants.

(cherry picked from commit efdf2cb)
(cherry picked from commit 6995a3a)
endel pushed a commit to endel/libxev that referenced this pull request Sep 26, 2026
…xt in submit

Bug mitchellh#209: kqueue tick(0) EV_DELETE flush
- Changed early exit condition from 'if (wait == 0) break' to
  'if (wait == 0 and changes == 0) break' so pending EV_DELETE
  kevent changes from the event-processing loop are flushed
  before tick(0) returns.

Bug mitchellh#170: rearm state correction
- When a non-kqueue completion (close, shutdown, threadpool
  fallback) returns .rearm, set flags.state to .adding before
  pushing to the submissions queue. Previously .dead state
  caused submit() to route through stop_completion (cancel)
  instead of start() (resubmit).

Issue mitchellh#169: defensive next-pointer clear in submit()
- Explicitly clear c.next before push to completions queue
  when processing kevent-returned events in submit(). This
  prevents an assertion failure if a completion is present
  in multiple queues concurrently (race condition).

(cherry picked from mitchellh#224; the .rearm arm is merged with
this fork's keep-active fix: a completion still registered with kqueue
stays .active, one never registered is resubmitted as .adding)

(cherry picked from commit a7502d6)
(cherry picked from commit 570e3b0)
endel pushed a commit to endel/libxev that referenced this pull request Oct 3, 2026
Add tests for two bugs:

Bug mitchellh#209: tick(0) EV_DELETE flush - kqueue tick(0) may leave
stale kernel filters when disarming. Six tests added covering
multiple disarms, write/read disarm on same fd, rapid cycles,
no-op tick, stale filter detection, and the kevent-event-processing
race path (fires without fix, passes with fix).

Bug mitchellh#170: rearm from non-kqueue completions - when a completion
that completes without kqueue registration returns .rearm, it
is pushed to submissions with .dead state which gets routed to
stop_completion instead of start. Integration test added (fails
without fix, passes with fix).

Queue unit tests added verifying re-enqueue across queues,
drain-and-refill, and rapid cycle invariants.

(cherry picked from commit efdf2cb)
(cherry picked from commit 6995a3a)
endel pushed a commit to endel/libxev that referenced this pull request Oct 3, 2026
…xt in submit

Bug mitchellh#209: kqueue tick(0) EV_DELETE flush
- Changed early exit condition from 'if (wait == 0) break' to
  'if (wait == 0 and changes == 0) break' so pending EV_DELETE
  kevent changes from the event-processing loop are flushed
  before tick(0) returns.

Bug mitchellh#170: rearm state correction
- When a non-kqueue completion (close, shutdown, threadpool
  fallback) returns .rearm, set flags.state to .adding before
  pushing to the submissions queue. Previously .dead state
  caused submit() to route through stop_completion (cancel)
  instead of start() (resubmit).

Issue mitchellh#169: defensive next-pointer clear in submit()
- Explicitly clear c.next before push to completions queue
  when processing kevent-returned events in submit(). This
  prevents an assertion failure if a completion is present
  in multiple queues concurrently (race condition).

(cherry picked from mitchellh#224; the .rearm arm is merged with
this fork's keep-active fix: a completion still registered with kqueue
stays .active, one never registered is resubmitted as .adding)

(cherry picked from commit a7502d6)
(cherry picked from commit 570e3b0)
endel pushed a commit to endel/libxev that referenced this pull request Oct 21, 2026
Add tests for two bugs:

Bug mitchellh#209: tick(0) EV_DELETE flush - kqueue tick(0) may leave
stale kernel filters when disarming. Six tests added covering
multiple disarms, write/read disarm on same fd, rapid cycles,
no-op tick, stale filter detection, and the kevent-event-processing
race path (fires without fix, passes with fix).

Bug mitchellh#170: rearm from non-kqueue completions - when a completion
that completes without kqueue registration returns .rearm, it
is pushed to submissions with .dead state which gets routed to
stop_completion instead of start. Integration test added (fails
without fix, passes with fix).

Queue unit tests added verifying re-enqueue across queues,
drain-and-refill, and rapid cycle invariants.

(cherry picked from commit efdf2cb)
(cherry picked from commit 6995a3a)
endel pushed a commit to endel/libxev that referenced this pull request Oct 21, 2026
…xt in submit

Bug mitchellh#209: kqueue tick(0) EV_DELETE flush
- Changed early exit condition from 'if (wait == 0) break' to
  'if (wait == 0 and changes == 0) break' so pending EV_DELETE
  kevent changes from the event-processing loop are flushed
  before tick(0) returns.

Bug mitchellh#170: rearm state correction
- When a non-kqueue completion (close, shutdown, threadpool
  fallback) returns .rearm, set flags.state to .adding before
  pushing to the submissions queue. Previously .dead state
  caused submit() to route through stop_completion (cancel)
  instead of start() (resubmit).

Issue mitchellh#169: defensive next-pointer clear in submit()
- Explicitly clear c.next before push to completions queue
  when processing kevent-returned events in submit(). This
  prevents an assertion failure if a completion is present
  in multiple queues concurrently (race condition).

(cherry picked from mitchellh#224; the .rearm arm is merged with
this fork's keep-active fix: a completion still registered with kqueue
stays .active, one never registered is resubmitted as .adding)

(cherry picked from commit a7502d6)
(cherry picked from commit 570e3b0)
endel pushed a commit to endel/libxev that referenced this pull request Oct 23, 2026
Add tests for two bugs:

Bug mitchellh#209: tick(0) EV_DELETE flush - kqueue tick(0) may leave
stale kernel filters when disarming. Six tests added covering
multiple disarms, write/read disarm on same fd, rapid cycles,
no-op tick, stale filter detection, and the kevent-event-processing
race path (fires without fix, passes with fix).

Bug mitchellh#170: rearm from non-kqueue completions - when a completion
that completes without kqueue registration returns .rearm, it
is pushed to submissions with .dead state which gets routed to
stop_completion instead of start. Integration test added (fails
without fix, passes with fix).

Queue unit tests added verifying re-enqueue across queues,
drain-and-refill, and rapid cycle invariants.

(cherry picked from commit efdf2cb)
(cherry picked from commit 6995a3a)
endel pushed a commit to endel/libxev that referenced this pull request Oct 23, 2026
…xt in submit

Bug mitchellh#209: kqueue tick(0) EV_DELETE flush
- Changed early exit condition from 'if (wait == 0) break' to
  'if (wait == 0 and changes == 0) break' so pending EV_DELETE
  kevent changes from the event-processing loop are flushed
  before tick(0) returns.

Bug mitchellh#170: rearm state correction
- When a non-kqueue completion (close, shutdown, threadpool
  fallback) returns .rearm, set flags.state to .adding before
  pushing to the submissions queue. Previously .dead state
  caused submit() to route through stop_completion (cancel)
  instead of start() (resubmit).

Issue mitchellh#169: defensive next-pointer clear in submit()
- Explicitly clear c.next before push to completions queue
  when processing kevent-returned events in submit(). This
  prevents an assertion failure if a completion is present
  in multiple queues concurrently (race condition).

(cherry picked from mitchellh#224; the .rearm arm is merged with
this fork's keep-active fix: a completion still registered with kqueue
stays .active, one never registered is resubmitted as .adding)

(cherry picked from commit a7502d6)
(cherry picked from commit 570e3b0)
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.

[bug] v.next is not proper cleared for re-enqueue a completion between different queues

2 participants