From 48b9910b97c650c2f62006eb6806ffcf328c3a53 Mon Sep 17 00:00:00 2001 From: Andrii Babanin Date: Sat, 24 May 2025 14:13:03 +0300 Subject: [PATCH] Cancel recovery CTS on connection Dispose --- .../Impl/AutorecoveringConnection.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs b/projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs index 817bf0101..788ef088a 100644 --- a/projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs +++ b/projects/RabbitMQ.Client/Impl/AutorecoveringConnection.cs @@ -292,6 +292,20 @@ public async ValueTask DisposeAsync() return; } + try + { +#if NETSTANDARD2_0 + _recoveryCancellationTokenSource.Cancel(); +#else + await _recoveryCancellationTokenSource.CancelAsync() + .ConfigureAwait(false); +#endif + } + catch + { + // Ensure dispose does not throw any exceptions. + } + try { await _innerConnection.DisposeAsync()