diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs index 723114ff7..4a2f0ce36 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Commands.cs @@ -50,8 +50,8 @@ public Task UpdateSecretAsync(string newSecret, string reason) internal void NotifyReceivedCloseOk() { - _closed = true; MaybeTerminateMainloopAndStopHeartbeatTimers(cancelMainLoop: true); + _closed = true; } internal void HandleConnectionBlocked(string reason) diff --git a/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs b/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs index 11827c7cd..97b3b900d 100644 --- a/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs +++ b/projects/RabbitMQ.Client/client/impl/Connection.Heartbeat.cs @@ -117,7 +117,12 @@ private async void HeartbeatReadTimerCallback(object? state) if (shouldTerminate) { MaybeTerminateMainloopAndStopHeartbeatTimers(); - await FinishCloseAsync(_mainLoopCts.Token) + /* + * Note: do NOT use the main loop cancellation token, + * because FininshCloseAsync immediately cancels it + */ + using var cts = new CancellationTokenSource(InternalConstants.DefaultConnectionAbortTimeout); + await FinishCloseAsync(cts.Token) .ConfigureAwait(false); } else