From a93a680e03b756e5334e386c44a66d47745ab33f Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 27 Aug 2018 11:48:32 -0400 Subject: [PATCH] Supress errors from cancelled requests. Log them as debug --- .../Controllers/ApiController.cs | 9 ++++++++- src/Tgstation.Server.Host/Core/Application.cs | 2 ++ .../Core/ApplicationBuilderExtensions.cs | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Tgstation.Server.Host/Controllers/ApiController.cs b/src/Tgstation.Server.Host/Controllers/ApiController.cs index 9d89a62b52..16fa1704dd 100644 --- a/src/Tgstation.Server.Host/Controllers/ApiController.cs +++ b/src/Tgstation.Server.Host/Controllers/ApiController.cs @@ -203,7 +203,14 @@ namespace Tgstation.Server.Host.Controllers Logger.LogDebug("Request made by User ID {0}. Api version: {1}. User-Agent: {2}. Type: {3}. Route {4}{5} to Instance {6}", AuthenticationContext?.User.Id.ToString(CultureInfo.InvariantCulture), ApiHeaders.ApiVersion, ApiHeaders.UserAgent, Request.Method, Request.Path, Request.QueryString, ApiHeaders.InstanceId); - await base.OnActionExecutionAsync(context, next).ConfigureAwait(false); + try + { + await base.OnActionExecutionAsync(context, next).ConfigureAwait(false); + } + catch (OperationCanceledException e) + { + Logger.LogDebug("Request cancelled! Exception: {0}", e); + } } } } diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 743ed7b490..556c2d1fbe 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -244,6 +244,8 @@ namespace Tgstation.Server.Host.Core applicationBuilder.UseDbConflictHandling(); + applicationBuilder.UseCancelledRequestSuppression(); + applicationBuilder.UseMvc(); } diff --git a/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs b/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs index b86e780895..becd3e5ad6 100644 --- a/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs +++ b/src/Tgstation.Server.Host/Core/ApplicationBuilderExtensions.cs @@ -35,5 +35,23 @@ namespace Tgstation.Server.Host.Core } }); } + + /// + /// Suppress TaskCanceledException warnings when a user aborts a request + /// + /// The to configure + public static void UseCancelledRequestSuppression(this IApplicationBuilder applicationBuilder) + { + if (applicationBuilder == null) + throw new ArgumentNullException(nameof(applicationBuilder)); + applicationBuilder.Use(async (context, next) => + { + try + { + await next().ConfigureAwait(false); + } + catch (OperationCanceledException) { } + }); + } } }