rabbitmq / rabbitmq-dotnet-client

RabbitMQ .NET client for .NET Standard 2.0+ and .NET 4.6.2+
https://www.rabbitmq.com/dotnet.html
Other
2.05k stars 575 forks source link

Add test that demonstrates the current behavior of a recovered channe… #1450

Closed lukebakken closed 6 months ago

lukebakken commented 6 months ago

…l that is disposed.

Fixes #1086

michaelklishin commented 6 months ago

I don't know how common it is in the .NET ecosystem to forcefully close a connection (channel, etc) in Dispose. I assume that close it in a destructor (or similar) would be even less evident?

paulomorgado commented 6 months ago

@michaelklishin, Close-like invocation in Dispose is very common and recommended.

Finalizers (destructors) should be used as a last resource and handle only unmanaged resources, as it is not guaranteed that all managed objects the class was referencing are still "alive" at the time the finalizer is invoked.

Also, using a finalizer requires one more step from the GC and will leave them in memory longer. Not to mention badly implemented finalizers that can deadlock or take down a process.

The common practice is for the Dispose method to suppress the execution of the finalizer when invoked.

For more information, refer to Cleaning up unmanaged resources and sub-sections.

lukebakken commented 6 months ago

Thanks for the input @michaelklishin and @paulomorgado