Skip to content

fix(operator): consume the timed entity queue without blocking a thread pool thread - #1313

Merged
kimpenhaus merged 2 commits into
mainfrom
fix/timed-entity-queue-async-consumer
Nov 7, 2026
Merged

kimpenhaus merged 2 commits into
mainfrom
fix/timed-entity-queue-async-consumer

Conversation

@kimpenhaus

Copy link
Copy Markdown
Collaborator

Closes #1308.

Problem

TimedEntityQueue<TEntity>.GetAsyncEnumerator consumed its BlockingCollection via GetConsumingEnumerable inside an async iterator. Every consumer therefore blocked a thread pool thread for its whole lifetime — one per entity type — and the queue's timer loop and all other async work competed for the remaining threads.

Changes

  • The ready queue is an unbounded Channel<QueueEntry<TEntity>>; GetAsyncEnumerator reads it with ReadAllAsync. Multiple readers stay allowed, since a leadership flap can briefly overlap two consumer loops.
  • Clear() drains via TryRead and never completes the channel, so the queue stays usable after ResumeIntake().
  • Dispose() completes the channel, which ends running consumers gracefully (previously they would have hit the disposed collection).
  • Docs: the custom queue section of queue-strategy.mdx now recommends an asynchronous wait for custom ITimedEntityQueue<TEntity> implementations.

Test

New regression test Waiting_For_Entries_Should_Not_Block_The_Consumer_Thread (area ThreadPool): the consumer and a probe run on a scheduler that executes one task at a time, in order. A consumer that blocks its thread while the queue is empty keeps the probe from ever running; an asynchronous consumer releases the scheduler while it waits. The test is deterministic and does not depend on timing.

  • before the fix: fails after its 5 s bound
  • after the fix: passes in ~45 ms

The full test suite passes (843 tests, 8 skipped).

…ad pool thread

TimedEntityQueue consumed its BlockingCollection via GetConsumingEnumerable
inside an async iterator, so every consumer blocked a thread pool thread for
its whole lifetime. Back the ready queue with an unbounded Channel<T> and read
it asynchronously. Disposing the queue completes the channel, which ends
running consumers.

Closes #1308.
@kimpenhaus
kimpenhaus enabled auto-merge (squash) November 7, 2026 11:06
@kimpenhaus
kimpenhaus merged commit 0ee3b59 into main Nov 7, 2026
5 checks passed
@kimpenhaus
kimpenhaus deleted the fix/timed-entity-queue-async-consumer branch November 7, 2026 11:15
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 13.3.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: TimedEntityQueue consumer blocks a thread pool thread

1 participant