Skip to content

Commit a667d9a

Browse files
committed
* Better cancellation token handling in CloseAsync
1 parent 23f6fda commit a667d9a

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

projects/RabbitMQ.Client/Impl/Channel.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ public Task CloseAsync(ushort replyCode, string replyText, bool abort,
208208
public async Task CloseAsync(ShutdownEventArgs args, bool abort,
209209
CancellationToken cancellationToken)
210210
{
211-
CancellationToken originalCancellationToken = cancellationToken;
212-
bool cancellationRequested = cancellationToken.IsCancellationRequested;
213-
if (IsOpen && cancellationRequested)
211+
CancellationToken argCancellationToken = cancellationToken;
212+
if (IsOpen)
214213
{
215214
// Note: we really do need to try and close this channel!
216215
cancellationToken = CancellationToken.None;
@@ -267,7 +266,7 @@ await ConsumerDispatcher.WaitForShutdownAsync()
267266
MaybeDisposeContinuation(enqueued, k);
268267
_rpcSemaphore.Release();
269268
ChannelShutdownAsync -= k.OnConnectionShutdownAsync;
270-
originalCancellationToken.ThrowIfCancellationRequested();
269+
argCancellationToken.ThrowIfCancellationRequested();
271270
}
272271
}
273272

projects/RabbitMQ.Client/Impl/Connection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ public Task CloseAsync(ushort reasonCode, string reasonText, TimeSpan timeout, b
320320
///</remarks>
321321
internal async Task CloseAsync(ShutdownEventArgs reason, bool abort, TimeSpan timeout, CancellationToken cancellationToken)
322322
{
323+
CancellationToken argCancellationToken = cancellationToken;
324+
323325
if (timeout < InternalConstants.DefaultConnectionAbortTimeout)
324326
{
325327
timeout = InternalConstants.DefaultConnectionAbortTimeout;
@@ -424,6 +426,8 @@ await _frameHandler.CloseAsync(cts.Token)
424426
throw;
425427
}
426428
}
429+
430+
argCancellationToken.ThrowIfCancellationRequested();
427431
}
428432

429433
internal async Task ClosedViaPeerAsync(ShutdownEventArgs reason, CancellationToken cancellationToken)

0 commit comments

Comments
 (0)