Channel is closed after Channel.ExchangeDeclarePassive fails
bodhi-code opened this issue · 1 comments
Description:
When using the Channel.ExchangeDeclarePassive method to check if an exchange exists, the channel is closed if the exchange does not exist. This behavior prevents subsequent operations from being performed.
Steps to Reproduce:
Create a RabbitMQ connection and channel.
Use the Channel.ExchangeDeclarePassive method to check for an exchange that does not exist.
Observe that the channel is closed after the operation fails.
Expected Behavior:
The channel should remain open even if the exchange does not exist, allowing for further operations such as creating the exchange or handling other tasks.
Actual Behavior:
The channel is closed, preventing any further operations on the channel.
Code Example:
err = channel.ExchangeDeclarePassive(exchangeName, "direct", true, false, false, false, nil)
if err != nil {
fmt.Printf("failed to check exchange: %+v\n", err)
}
fmt.Printf("channel is closed:%+v", channel.IsClosed())
Environment:
Go version: [1.22.3]
github.com/rabbitmq/amqp091-go version: [v.1.10.0]
Additional Context:
The issue occurs when the exchange does not exist and the ExchangeDeclarePassive method is called.
The channel is closed, which prevents further operations on the channel.
Possible Solution:
Ensure that the channel remains open even if the exchange does not exist.
Provide a way to handle the 404 error without closing the channel.
This is working as expected, following AMQP 0.9.1 protocol for exchange declare with passive bit set.
If set, the server will reply with Declare-Ok if the exchange already exists with the same name, and raise an error if not.
The server raises an error, which results in a channel closed, and an event sent to any listener of Channel.NotifyClose
.