-
Notifications
You must be signed in to change notification settings - Fork 612
Description
Describe the bug
I have a setup with one RabbitMQ server (Version 3.13.7) and two clients (Version 6.8.1). One client manages the queues, while the other subscribes to them. When the second client attempts to cancel its consumers after the first client has deleted the queues, it throws a NullReferenceException.
Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object. at RabbitMQ.Client.Impl.ModelBase.BasicCancel(String consumerTag) at RabbitMQ.Client.Impl.AutorecoveringModel.BasicCancel(String consumerTag) at Program.<Main>$(String[] args) in C:\Users\silbersm\Work\Repos\TestProjects\TestConsole\TestConsole\Program.cs:line 17
The workaround is to set the DefaultConsumer on the second client's model to any consumer instance.
Reproduction steps
Here are the steps to reproduce the behavior:
- Start the RabbitMQ server.
- Create two client connections and two models.
- Use one model and connection pair to create a queue and subscribe a consumer.
- The second pair then deletes the queue.
- The first pair's model calls BasicCancel() with the consumer's tag.
A small .NET 8 test project is provided to reproduce this behavior consistently, containing the following files:
- csproj
- docker-compose.yml
- Program.cs
I am using Windows 11 with Podman as my container runtime.
Expected behavior
I expect that the library can BasicCancel the consumer gracefully without exception.
Additional context
The exception is thrown when the ModelShutdown EventHandler is deregistered from the consumer that does not exist anymore.