From c502374ef3c4a31f351ef2a33eb50d831954441b Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 21 May 2024 16:13:03 -0700 Subject: [PATCH 1/2] Fix ShutdownInitiator in `CloseAsync` `AutorecoveringChannel` `CloseAsync` should just call `_innerChannel.CloseAsync` --- projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs | 3 +-- projects/Test/Applications/MassPublish/Program.cs | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs index 19d60e7479..f0c6e09628 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs @@ -204,8 +204,7 @@ public Task CloseAsync(ushort replyCode, string replyText, bool abort, CancellationToken cancellationToken) { ThrowIfDisposed(); - var args = new ShutdownEventArgs(ShutdownInitiator.Library, replyCode, replyText); - return CloseAsync(args, abort, cancellationToken); + return _innerChannel.CloseAsync(replyCode, replyText, abort, cancellationToken); } public async Task CloseAsync(ShutdownEventArgs args, bool abort, diff --git a/projects/Test/Applications/MassPublish/Program.cs b/projects/Test/Applications/MassPublish/Program.cs index a3938b69a8..57bcdd9b72 100644 --- a/projects/Test/Applications/MassPublish/Program.cs +++ b/projects/Test/Applications/MassPublish/Program.cs @@ -156,6 +156,7 @@ await publishChannel.BasicPublishAsync(exchange: ExchangeName, routingKey: Routi } await consumeChannel.CloseAsync(); + await consumeConnection.CloseAsync(); } private static void PublishChannel_BasicNacks(object sender, BasicNackEventArgs e) From f445f2d363734154d71f6a126ae4b36bbecba7dd Mon Sep 17 00:00:00 2001 From: Luke Bakken Date: Tue, 21 May 2024 16:40:49 -0700 Subject: [PATCH 2/2] fixup --- .../client/impl/AutorecoveringChannel.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs index f0c6e09628..317099a078 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs @@ -200,11 +200,21 @@ await _connection.RecoverConsumersAsync(this, newChannel, recordedEntitiesSemaph _innerChannel.RunRecoveryEventHandlers(this); } - public Task CloseAsync(ushort replyCode, string replyText, bool abort, + public async Task CloseAsync(ushort replyCode, string replyText, bool abort, CancellationToken cancellationToken) { ThrowIfDisposed(); - return _innerChannel.CloseAsync(replyCode, replyText, abort, cancellationToken); + try + { + await _innerChannel.CloseAsync(replyCode, replyText, abort, cancellationToken) + .ConfigureAwait(false); + } + finally + { + await _connection.DeleteRecordedChannelAsync(this, + channelsSemaphoreHeld: false, recordedEntitiesSemaphoreHeld: false) + .ConfigureAwait(false); + } } public async Task CloseAsync(ShutdownEventArgs args, bool abort,