diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs index c39c8be65..8d996c082 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs @@ -197,7 +197,7 @@ await newChannel.TxSelectAsync(cancellationToken) if (_disposed) { - await newChannel.AbortAsync() + await newChannel.AbortAsync(CancellationToken.None) .ConfigureAwait(false); return false; } @@ -207,7 +207,7 @@ await newChannel.AbortAsync() if (recoverConsumers) { - await _connection.RecoverConsumersAsync(this, newChannel, recordedEntitiesSemaphoreHeld) + await _connection.RecoverConsumersAsync(this, newChannel, recordedEntitiesSemaphoreHeld, cancellationToken) .ConfigureAwait(false); } diff --git a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs index 4d4846363..3dcf20d56 100644 --- a/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs +++ b/projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs @@ -77,8 +77,7 @@ static bool ShouldTriggerConnectionRecovery(ShutdownEventArgs args) * https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/826 * Happens when an AppDomain is unloaded */ - if (args.Exception is ThreadAbortException && - args.ReplyCode == Constants.InternalError) + if (args is { Exception: ThreadAbortException, ReplyCode: Constants.InternalError }) { return false; } @@ -407,7 +406,7 @@ await _config.TopologyRecoveryExceptionHandler.QueueRecoveryExceptionHandlerAsyn } finally { - await _recordedEntitiesSemaphore.WaitAsync() + await _recordedEntitiesSemaphore.WaitAsync(cancellationToken) .ConfigureAwait(false); } } @@ -494,7 +493,7 @@ await _recordedEntitiesSemaphore.WaitAsync(cancellationToken) } internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRecover, IChannel channelToUse, - bool recordedEntitiesSemaphoreHeld = false) + bool recordedEntitiesSemaphoreHeld = false, CancellationToken cancellationToken = default) { if (_disposed) { @@ -520,7 +519,8 @@ internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRe } finally { - _recordedEntitiesSemaphore.Wait(); + await _recordedEntitiesSemaphore.WaitAsync(cancellationToken) + .ConfigureAwait(false); } string oldTag = consumer.ConsumerTag; @@ -540,7 +540,7 @@ internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRe } finally { - await _recordedEntitiesSemaphore.WaitAsync() + await _recordedEntitiesSemaphore.WaitAsync(cancellationToken) .ConfigureAwait(false); } } @@ -558,7 +558,7 @@ await _config.TopologyRecoveryExceptionHandler.ConsumerRecoveryExceptionHandlerA } finally { - await _recordedEntitiesSemaphore.WaitAsync() + await _recordedEntitiesSemaphore.WaitAsync(cancellationToken) .ConfigureAwait(false); } }