-
Notifications
You must be signed in to change notification settings - Fork 606
Unexpected AMQP close-reason, initiated by Peer, code=504, text='CHANNEL_ERROR - expected 'channel.open' #1835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Some log RabbitMQ 2025-05-16 15:50:38 2025-05-16 12:50:38.294140+00:00 [error] <0.102182.0> Channel error on connection <0.101966.0> (172.22.0.1:39782 -> 172.22.0.2:5672, vhost: '/', user: 'guest'), channel 1: |
Hello, thanks for this report and for code to reproduce the issue. I created a complete project here: https://github.com/lukebakken/rabbitmq-dotnet-client-1835 Here is the problem:
I'm not sure if it's possible to "do better" in this scenario. It is always possible that, without using publisher confirmations, a client application could send I'm going to remove the "bug" label for now while I investigate. |
Ok, I can reproduce the problem too. Will start looking. |
@lukebakken I don't think this is a client issue. My opinion: I would not change the client to deal with a non-real use case like this. The code like this is enough to solve the problem. using RabbitMQ.Client;
using RabbitMQ.Client.Events;
using RabbitMQ.Client.Exceptions;
using System.Net.Mime;
using System.Text;
var factory = new ConnectionFactory
{
HostName = "localhost",
Port = 5672,
UserName = "guest",
Password = "guest"
};
var connection = await factory.CreateConnectionAsync();
connection.ConnectionShutdownAsync += Connection_ConnectionShutdownAsync;
var options = new CreateChannelOptions(false, false);
var json = "{ \"A\" : \"X\"}";
var body = Encoding.UTF8.GetBytes(json);
var bp = new BasicProperties
{
ContentType = MediaTypeNames.Application.Json,
ContentEncoding = "UTF-8",
};
IChannel channel = await connection.CreateChannelAsync(options);
channel.ChannelShutdownAsync += Channel_ChannelShutdownAsync;
while (true)
{
try
{
await channel.BasicPublishAsync("NotExistsExchange", String.Empty, true, bp, body);
Console.WriteLine("after BasicPublishAsync");
}
catch (AlreadyClosedException)
{
Console.WriteLine("caught AlreadyClosedException");
}
if (channel.IsClosed)
{
int retry = 0;
while (retry < 3)
{
Console.WriteLine("channel.IsClosed is true, retrying...");
await Task.Delay(1000);
Console.WriteLine("channel.IsClosed is true");
try
{
if (!connection.IsOpen)
{
Console.WriteLine("connection.IsOpen is false, retrying...");
connection.ConnectionShutdownAsync -= Connection_ConnectionShutdownAsync;
connection = await factory.CreateConnectionAsync();
connection.ConnectionShutdownAsync += Connection_ConnectionShutdownAsync;
}
channel.ChannelShutdownAsync -= Channel_ChannelShutdownAsync;
channel = await connection.CreateChannelAsync(options); // The error occurs here
channel.ChannelShutdownAsync += Channel_ChannelShutdownAsync;
Console.WriteLine("channel recreated successfully");
break;
}
catch (Exception e)
{
Console.WriteLine("Exception during channel recreation: " + e.Message);
}
retry++;
}
}
}
static Task Connection_ConnectionShutdownAsync(object sender, ShutdownEventArgs @event)
{
Console.WriteLine("Connection shutdown: " + @event.ReplyCode);
return Task.CompletedTask;
}
static Task Channel_ChannelShutdownAsync(object sender, ShutdownEventArgs @event)
{
Console.WriteLine("Channel shutdown: " + @event.ReplyCode);
return Task.CompletedTask;
} |
(I'm mentioning this for the readers who are not core team members, not insulting Gabriele's intelligence ;)) All RabbitMQ clients maintained by our team perform connection recovery after a delay. Are you suggesting a small delay between channel recovery? That's a reasonable idea but with a large number of channels — whether we recommend it or not, there is no shortage of such apps — can result in significant recovery delays. Or is your recommendation against such a delay? |
Yes. I suggest adding a delay (a back-off would be better), as we do for other clients. I am thinking of the stream clients experience. That's my opinion, based on the experiences of other clients, but I am open to discussing |
I will close the issue. Feel free to reopen in case needed. |
Uh oh!
There was an error while loading. Please reload this page.
Describe the bug
Endless sending of messages to a non-existent exchange when PublisherConfirmationsEnabled = false or PublisherConfirmationsEnabled = true and PublisherConfirmationTrackingEnabled = false.
Attached is a sample code that causes the error. Is this normal behavior or not?
And why?
At
PublisherConfirmationsEnabled = true
PublisherConfirmationTrackingEnabled = true
It works correctly
RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=504, text='CHANNEL_ERROR - expected 'channel.open'', classId=60, methodId=40
Reproduction steps
Expected behavior
Works stably
Additional context
The text was updated successfully, but these errors were encountered: