Skip to content

fix: adapt Azure Service Bus MessageBus to two-phase dispose lifecycle#77

Merged
niemyjski merged 7 commits into
mainfrom
fix/messagebus-subscription-lifecycle
Apr 15, 2026
Merged

fix: adapt Azure Service Bus MessageBus to two-phase dispose lifecycle#77
niemyjski merged 7 commits into
mainfrom
fix/messagebus-subscription-lifecycle

Conversation

@niemyjski
Copy link
Copy Markdown
Member

Summary

  • Add \ShutdownAsync\ override calling \StopProcessingAsync\ for graceful drain
  • Add \CleanupAsync\ override for processor/sender/client disposal
  • Handle \OperationCanceledException\ in \OnMessageAsync\ to abandon messages for redelivery
  • Remove ad-hoc Dispose/DisposeAsync and private cleanup methods

Dependencies

Test plan

  • Builds with local Foundatio source (\ReferenceFoundatioSource=true)
  • CI runs integration tests with Azure Service Bus

- Add ShutdownAsync override for StopProcessingAsync
- Add CleanupAsync override for processor/sender/client disposal
- Handle OperationCanceledException in OnMessageAsync
- Remove ad-hoc Dispose/DisposeAsync
- Depends on FoundatioFx/Foundatio#492
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adapts AzureServiceBusMessageBus to Foundatio’s new two-phase disposal lifecycle (shutdown/drain first, then cleanup), and updates the Azure Service Bus test suite to exercise the new async dispose semantics.

Changes:

  • Replace ad-hoc Dispose/DisposeAsync + private cleanup helpers with ShutdownAsync (drain) and CleanupAsync (dispose resources).
  • Update message handling to catch OperationCanceledException during dispose.
  • Extend/adjust Azure Service Bus message bus tests to cover new dispose behaviors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/Foundatio.AzureServiceBus.Tests/Messaging/AzureServiceBusMessageBusTests.cs Updates/extends base test overrides to validate async dispose lifecycle behavior for the ASB bus.
src/Foundatio.AzureServiceBus/Messaging/AzureServiceBusMessageBus.cs Implements two-phase dispose (ShutdownAsync + CleanupAsync) and tweaks message processing error handling during disposal.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Foundatio.AzureServiceBus/Messaging/AzureServiceBusMessageBus.cs Outdated
@niemyjski niemyjski force-pushed the fix/messagebus-subscription-lifecycle branch from 4ea90ee to ed06a7d Compare April 15, 2026 01:30
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Azure Service Bus message bus implementation to align with Foundatio’s new two-phase dispose lifecycle (graceful shutdown/drain followed by resource cleanup), and updates tests/packages accordingly.

Changes:

  • Refactors AzureServiceBusMessageBus cleanup to use lifecycle overrides instead of ad-hoc Dispose/DisposeAsync implementations.
  • Adjusts message handling during disposal by rethrowing OperationCanceledException (to avoid message auto-complete).
  • Updates Foundatio/Foundatio.TestHarness package references and refreshes test coverage around disposal behaviors.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Foundatio.AzureServiceBus/Messaging/AzureServiceBusMessageBus.cs Moves disposal logic into lifecycle overrides and tweaks cancellation behavior in message processing.
src/Foundatio.AzureServiceBus/Foundatio.AzureServiceBus.csproj Bumps Foundatio dependency to 13.0.0-beta5.2.
tests/Directory.Build.props Bumps Foundatio.TestHarness dependency to 13.0.0-beta5.2.
tests/Foundatio.AzureServiceBus.Tests/Messaging/AzureServiceBusMessageBusTests.cs Updates/expands test overrides to match new disposal lifecycle expectations.
samples/Foundatio.AzureServiceBus.Subscribe/Program.cs Minor formatting change in catch block.
samples/Foundatio.AzureServiceBus.Dequeue/Program.cs Minor formatting change in catch block.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

return;
using (await _lock.LockAsync().AnyContext())
{
if (_subscriptionProcessor is not null)
{
using (await _lock.LockAsync().AnyContext())
{
if (_topicSender is not null)
@niemyjski niemyjski merged commit 2055034 into main Apr 15, 2026
4 checks passed
@niemyjski niemyjski deleted the fix/messagebus-subscription-lifecycle branch April 15, 2026 17:35
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.

2 participants