From cfd974337da492149fd7bb55688286d8b603b64b Mon Sep 17 00:00:00 2001 From: "Chris Ross (ASP.NET)" Date: Fri, 3 Nov 2017 09:45:45 -0700 Subject: [PATCH] Improved request error handling. --- .../AsyncAcceptContext.cs | 6 ++++++ src/Microsoft.AspNetCore.Server.HttpSys/HttpSysListener.cs | 2 +- src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.AspNetCore.Server.HttpSys/AsyncAcceptContext.cs b/src/Microsoft.AspNetCore.Server.HttpSys/AsyncAcceptContext.cs index 01e74c1990..4c0cd86756 100644 --- a/src/Microsoft.AspNetCore.Server.HttpSys/AsyncAcceptContext.cs +++ b/src/Microsoft.AspNetCore.Server.HttpSys/AsyncAcceptContext.cs @@ -6,6 +6,7 @@ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.HttpSys.Internal; namespace Microsoft.AspNetCore.Server.HttpSys @@ -80,6 +81,11 @@ namespace Microsoft.AspNetCore.Server.HttpSys complete = true; } } + catch (Exception) + { + server.SendError(asyncResult._nativeRequestContext.RequestId, StatusCodes.Status400BadRequest); + throw; + } finally { // The request has been handed to the user, which means this code can't reuse the blob. Reset it here. diff --git a/src/Microsoft.AspNetCore.Server.HttpSys/HttpSysListener.cs b/src/Microsoft.AspNetCore.Server.HttpSys/HttpSysListener.cs index 2c70016e3f..a1ad7493d8 100644 --- a/src/Microsoft.AspNetCore.Server.HttpSys/HttpSysListener.cs +++ b/src/Microsoft.AspNetCore.Server.HttpSys/HttpSysListener.cs @@ -316,7 +316,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys return true; } - private unsafe void SendError(ulong requestId, int httpStatusCode, IList authChallenges) + internal unsafe void SendError(ulong requestId, int httpStatusCode, IList authChallenges = null) { HttpApiTypes.HTTP_RESPONSE_V2 httpResponse = new HttpApiTypes.HTTP_RESPONSE_V2(); httpResponse.Response_V1.Version = new HttpApiTypes.HTTP_VERSION(); diff --git a/src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs b/src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs index 2b06066936..e70c52d89c 100644 --- a/src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs +++ b/src/Microsoft.AspNetCore.Server.HttpSys/MessagePump.cs @@ -168,7 +168,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys { LogHelper.LogException(_logger, "ListenForNextRequestAsync", exception); } - return; + continue; } try {