Skip to content

Calling Dispose on AutorecoveringModel that has already shutdown throws NullRefException #825

Closed
@stebet

Description

@stebet

Just hit this issue during testing in one our systems, where we try to restart a consumer if it has shutdown. For good measure, we decided to call .Dispose on the Model in the consumer, which threw an exception in the AutorecoveringModel.Abort() method.

"Object reference not set to an instance of an object." at RabbitMQ.Client.Impl.AutorecoveringModel.Abort()
   at RabbitMQ.Client.Impl.AutorecoveringModel.System.IDisposable.Dispose()
   at CCP.Protobuf.RabbitMQ.EveRabbitMQProtoSubscriber.StartEventSubscriber()
   at CCP.Protobuf.RabbitMQ.EveRabbitMQProtoSubscriber.OnEventConsumerShutdown(Object sender, ShutdownEventArgs event)

Calling .Dispose should never throw an exception, as it is often called in finally blocks. See here: https://docs.microsoft.com/en-us/visualstudio/code-quality/ca1065?view=vs-2019

A System.IDisposable.Dispose method should not throw an exception. Dispose is often called as part of the cleanup logic in a finally clause. Therefore, explicitly throwing an exception from Dispose forces the user to add exception handling inside the finally clause.

The Dispose(false) code path should never throw exceptions, because Dispose is almost always called from a finalizer.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions