From 78d605339e2c4635256b21fbe1ee61c8fc438e6d Mon Sep 17 00:00:00 2001 From: Michael Klishin Date: Wed, 23 Feb 2022 17:17:29 +0300 Subject: [PATCH] Merge pull request #1154 from ricado-group/1153-semaphore-disposed-exception Fix for #1153 - Semaphore disposed before discarded tasks have finished (cherry picked from commit 0c953304402af7e3ac99cca44863e95fd0ed017f) --- .../client/impl/AsyncConsumerWorkService.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs b/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs index 6c3cc544aa..e19bf59b9b 100644 --- a/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs +++ b/projects/RabbitMQ.Client/client/impl/AsyncConsumerWorkService.cs @@ -178,7 +178,14 @@ private static async Task HandleConcurrent(Work work, IModel model, SemaphoreSli finally { work.PostExecute(); - limiter.Release(); + + try + { + limiter.Release(); + } + catch (ObjectDisposedException) // Prevents Exceptions in the Task's finalizer when the WorkPool is Stopped + { + } } }