Skip to content

Commit 2cc12a5

Browse files
Minor cleanup in AutoRecovery classes (#1670)
* AutorecoveringChannel use token * Pattern merge instead of if * Use async overload where possible --------- Co-authored-by: danielmarbach <[email protected]>
1 parent b2282c7 commit 2cc12a5

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

projects/RabbitMQ.Client/client/impl/AutorecoveringChannel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ await newChannel.TxSelectAsync(cancellationToken)
197197

198198
if (_disposed)
199199
{
200-
await newChannel.AbortAsync()
200+
await newChannel.AbortAsync(CancellationToken.None)
201201
.ConfigureAwait(false);
202202
return false;
203203
}
@@ -207,7 +207,7 @@ await newChannel.AbortAsync()
207207

208208
if (recoverConsumers)
209209
{
210-
await _connection.RecoverConsumersAsync(this, newChannel, recordedEntitiesSemaphoreHeld)
210+
await _connection.RecoverConsumersAsync(this, newChannel, recordedEntitiesSemaphoreHeld, cancellationToken)
211211
.ConfigureAwait(false);
212212
}
213213

projects/RabbitMQ.Client/client/impl/AutorecoveringConnection.Recovery.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ static bool ShouldTriggerConnectionRecovery(ShutdownEventArgs args)
7777
* https://github.com/rabbitmq/rabbitmq-dotnet-client/issues/826
7878
* Happens when an AppDomain is unloaded
7979
*/
80-
if (args.Exception is ThreadAbortException &&
81-
args.ReplyCode == Constants.InternalError)
80+
if (args is { Exception: ThreadAbortException, ReplyCode: Constants.InternalError })
8281
{
8382
return false;
8483
}
@@ -407,7 +406,7 @@ await _config.TopologyRecoveryExceptionHandler.QueueRecoveryExceptionHandlerAsyn
407406
}
408407
finally
409408
{
410-
await _recordedEntitiesSemaphore.WaitAsync()
409+
await _recordedEntitiesSemaphore.WaitAsync(cancellationToken)
411410
.ConfigureAwait(false);
412411
}
413412
}
@@ -494,7 +493,7 @@ await _recordedEntitiesSemaphore.WaitAsync(cancellationToken)
494493
}
495494

496495
internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRecover, IChannel channelToUse,
497-
bool recordedEntitiesSemaphoreHeld = false)
496+
bool recordedEntitiesSemaphoreHeld = false, CancellationToken cancellationToken = default)
498497
{
499498
if (_disposed)
500499
{
@@ -520,7 +519,8 @@ internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRe
520519
}
521520
finally
522521
{
523-
_recordedEntitiesSemaphore.Wait();
522+
await _recordedEntitiesSemaphore.WaitAsync(cancellationToken)
523+
.ConfigureAwait(false);
524524
}
525525

526526
string oldTag = consumer.ConsumerTag;
@@ -540,7 +540,7 @@ internal async ValueTask RecoverConsumersAsync(AutorecoveringChannel channelToRe
540540
}
541541
finally
542542
{
543-
await _recordedEntitiesSemaphore.WaitAsync()
543+
await _recordedEntitiesSemaphore.WaitAsync(cancellationToken)
544544
.ConfigureAwait(false);
545545
}
546546
}
@@ -558,7 +558,7 @@ await _config.TopologyRecoveryExceptionHandler.ConsumerRecoveryExceptionHandlerA
558558
}
559559
finally
560560
{
561-
await _recordedEntitiesSemaphore.WaitAsync()
561+
await _recordedEntitiesSemaphore.WaitAsync(cancellationToken)
562562
.ConfigureAwait(false);
563563
}
564564
}

0 commit comments

Comments
 (0)