From 0b7c84a119d140702b72376a58749d23b22a9e40 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Mon, 18 Jan 2021 14:17:07 +0100 Subject: [PATCH] Ignore OperationCanceledException as well when shutting down --- Tapeti/Connection/TapetiConsumer.cs | 9 +++++---- Tapeti/Default/ControllerBindingContext.cs | 1 - Tapeti/Default/ControllerMethodBinding.cs | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Tapeti/Connection/TapetiConsumer.cs b/Tapeti/Connection/TapetiConsumer.cs index 77b77f6..19fb870 100644 --- a/Tapeti/Connection/TapetiConsumer.cs +++ b/Tapeti/Connection/TapetiConsumer.cs @@ -134,7 +134,7 @@ namespace Tapeti.Connection private void HandleException(ExceptionStrategyContext exceptionContext) { - if (cancellationToken.IsCancellationRequested && IsTaskCanceledException(exceptionContext.Exception)) + if (cancellationToken.IsCancellationRequested && IgnoreExceptionDuringShutdown(exceptionContext.Exception)) { // The service is most likely stopping, and the connection is gone anyways. exceptionContext.SetConsumeResult(ConsumeResult.Requeue); @@ -156,18 +156,19 @@ namespace Tapeti.Connection } - private static bool IsTaskCanceledException(Exception e) + private static bool IgnoreExceptionDuringShutdown(Exception e) { switch (e) { case AggregateException aggregateException: - return aggregateException.InnerExceptions.Any(IsTaskCanceledException); + return aggregateException.InnerExceptions.Any(IgnoreExceptionDuringShutdown); case TaskCanceledException _: + case OperationCanceledException _: // thrown by CancellationTokenSource.ThrowIfCancellationRequested return true; default: - return e.InnerException != null && IsTaskCanceledException(e.InnerException); + return e.InnerException != null && IgnoreExceptionDuringShutdown(e.InnerException); } } diff --git a/Tapeti/Default/ControllerBindingContext.cs b/Tapeti/Default/ControllerBindingContext.cs index f86dc36..8eb0150 100644 --- a/Tapeti/Default/ControllerBindingContext.cs +++ b/Tapeti/Default/ControllerBindingContext.cs @@ -155,7 +155,6 @@ namespace Tapeti.Default public bool HasHandler => Handler != null; - /// public ControllerBindingResult(ParameterInfo info) { Info = info; diff --git a/Tapeti/Default/ControllerMethodBinding.cs b/Tapeti/Default/ControllerMethodBinding.cs index 4c334d8..1d52cb4 100644 --- a/Tapeti/Default/ControllerMethodBinding.cs +++ b/Tapeti/Default/ControllerMethodBinding.cs @@ -99,7 +99,6 @@ namespace Tapeti.Default public MethodInfo Method => bindingInfo.Method; - /// public ControllerMethodBinding(IDependencyResolver dependencyResolver, BindingInfo bindingInfo) { this.dependencyResolver = dependencyResolver;