WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f4c74d9

Browse files
authored
Do not return faulty IChannel to the pool (#1759)
1 parent 58ff2e0 commit f4c74d9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/DotNetCore.CAP.RabbitMQ/ITransport.RabbitMQ.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using DotNetCore.CAP.Transport;
1010
using Microsoft.Extensions.Logging;
1111
using RabbitMQ.Client;
12+
using RabbitMQ.Client.Exceptions;
1213

1314
namespace DotNetCore.CAP.RabbitMQ;
1415

@@ -49,6 +50,16 @@ public async Task<OperateResult> SendAsync(TransportMessage message)
4950
}
5051
catch (Exception ex)
5152
{
53+
if (ex is AlreadyClosedException && channel?.IsOpen == true)
54+
{
55+
// There are cases when channel's property IsOpen returns true, but the connection is actually closed, e.g. https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/1871
56+
// This is a workaround to abort the channel in this case to avoid returning a faulty channel back to the pool.
57+
58+
_logger.LogWarning("Channel state inconsistency detected: channel is reported as open, but its underlying connection is closed. Forcing channel closure.");
59+
60+
await channel.DisposeAsync();
61+
}
62+
5263
var wrapperEx = new PublisherSentFailedException(ex.Message, ex);
5364
var errors = new OperateError
5465
{

0 commit comments

Comments
 (0)