Skip to content

chore(bus): avoid stop thread hop#360

Merged
yordis merged 2 commits into
masterfrom
yordis/chore-bus-stop-directly
May 14, 2026
Merged

chore(bus): avoid stop thread hop#360
yordis merged 2 commits into
masterfrom
yordis/chore-bus-stop-directly

Conversation

@yordis

@yordis yordis commented May 14, 2026

Copy link
Copy Markdown
Member
  • Avoids spending shutdown capacity on redundant thread pool dispatch when queue stops already provide asynchronous completion.
  • Keeps shutdown failures and wait behavior observable under focused coverage.

Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@cursor

cursor Bot commented May 14, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes shutdown/concurrency behavior by invoking queue Stop() inline and aggregating both synchronous and asynchronous failures; issues could surface as hangs or different exception timing during shutdown.

Overview
MultiQueuedHandler.Stop() now calls each queue’s Stop() directly (instead of dispatching via Task.Run), wrapping synchronous throws into Task.FromException and still awaiting all stops via Task.WhenAll.

Adds focused tests to verify Stop() waits for all queues, propagates stop failures, and still attempts to stop remaining queues even when one Stop() throws synchronously.

Reviewed by Cursor Bugbot for commit 28f7589. Bugbot is set up for automated code reviews on this repo. Configure here.

@coderabbitai

coderabbitai Bot commented May 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Rate limit exceeded

@yordis has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 22 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f314b467-0b15-45a8-b8f3-23d26c810e7c

📥 Commits

Reviewing files that changed from the base of the PR and between 2f57f05 and 28f7589.

📒 Files selected for processing (2)
  • src/EventStore.Core.XUnit.Tests/Bus/MultiQueuedHandlerTests.cs
  • src/EventStore.Core/Bus/MultiQueuedHandler.cs

Walkthrough

MultiQueuedHandler.Stop() changes from wrapping per-queue stops in Task.Run to direct invocation, removing task factory overhead. RecordingQueuedHandler adds configurable stop task behavior, and two new async tests validate that the overall stop operation waits for all queues and propagates exceptions.

Changes

MultiQueuedHandler Stop Behavior

Layer / File(s) Summary
Stop behavior change and validation
src/EventStore.Core/Bus/MultiQueuedHandler.cs, src/EventStore.Core.XUnit.Tests/Bus/MultiQueuedHandlerTests.cs
MultiQueuedHandler.Stop() directly invokes queues[i].Stop() instead of wrapping in Task.Run(). RecordingQueuedHandler adds a StopTask property so tests can control queue stop behavior. Two new async tests verify that MultiQueuedHandler.Stop() waits for all queue stop tasks and propagates exceptions from failing queue stops.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • TrogonStack/TrogonEventStore#70: Updates MultiQueuedHandler.Stop() to call underlying queue stops directly and adds tests for awaiting/exception propagation, building on prior async queue-shutdown changes.

Poem

🐰 A handler stops with grace so true,
Tasks await, no wrapping brew,
Exceptions flow where they belong,
Direct calls make the queue dance strong! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: avoiding redundant thread hops in the bus stop mechanism, which directly relates to the implementation change in MultiQueuedHandler.
Description check ✅ Passed The description directly relates to the changeset by explaining the motivation: avoiding redundant thread pool dispatch and ensuring shutdown failures remain observable through test coverage.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch yordis/chore-bus-stop-directly

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

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/EventStore.Core/Bus/MultiQueuedHandler.cs`:
- Around line 49-52: MultiQueuedHandler.Stop currently calls queues[i].Stop()
directly into stopTasks[i], so a synchronous exception from a queue will
short-circuit the loop and prevent later queues from being stopped; fix this by
wrapping each call in a try/catch inside the loop in Stop: attempt to assign
stopTasks[i] = queues[i].Stop(), but if queues[i].Stop() throws synchronously
catch the exception and assign stopTasks[i] = Task.FromException(exception) (or
otherwise create a faulted Task) so the loop continues and all queues get a stop
invocation; reference MultiQueuedHandler.Stop, the queues array and stopTasks[]
when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: dc5df798-63e5-4454-85c9-4bac83b0e0f5

📥 Commits

Reviewing files that changed from the base of the PR and between 7373777 and 2f57f05.

📒 Files selected for processing (2)
  • src/EventStore.Core.XUnit.Tests/Bus/MultiQueuedHandlerTests.cs
  • src/EventStore.Core/Bus/MultiQueuedHandler.cs

Comment thread src/EventStore.Core/Bus/MultiQueuedHandler.cs
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
@yordis yordis merged commit 66c1211 into master May 14, 2026
22 checks passed
@yordis yordis deleted the yordis/chore-bus-stop-directly branch May 14, 2026 16:30
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