NServiceBus icon indicating copy to clipboard operation
NServiceBus copied to clipboard

Separate disposal from shutdown in the transport seam.

Open andreasohlund opened this issue 8 months ago • 1 comments

Describe the suggested improvement

To better align with dotnet guidance around resource disposal, our transport seam should separate Shutdown from resource disposal by making disposal (likely by requiring transports to implement IAsyncDisposable) explicit.

This will be one of the steps towards:

  • https://github.com/Particular/NServiceBus/issues/7322

Additional Context

No response

andreasohlund avatar Apr 02 '25 17:04 andreasohlund

To add here is that currently TransportInfrastructure.Shutdown does both stopping and disposing. Meaning the method currently has 2 responsibilities but implementations currently do not guarantee that resources are released.

The following PRs show how the transports could at least enforce releasing resources during shutdown:

  • https://github.com/Particular/NServiceBus.AmazonSQS/pull/2777
  • https://github.com/Particular/NServiceBus.Transport.Msmq/pull/810
  • https://github.com/Particular/NServiceBus.AzureStorageQueues/pull/1312
  • https://github.com/Particular/NServiceBus.SqlServer/pull/1541

However, there is no guaranteer that Shutdown gets invoked as we moved away from IDispobable which was present in v5 but no longer in v6+.

Also, shutdown behavior is to allow graceful stopping of receivers which can be timely. Dispose should not take much time and its only purpose is to release resources in the proper order to prevent runtime errors

ramonsmits avatar Apr 03 '25 12:04 ramonsmits