diff --git a/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestPipeReader.cs b/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestPipeReader.cs index b44d45e829..262e79f602 100644 --- a/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestPipeReader.cs +++ b/src/Servers/Kestrel/Core/src/Internal/Http/HttpRequestPipeReader.cs @@ -17,7 +17,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { private MessageBody _body; private HttpStreamState _state; - private Exception _error; + private ExceptionDispatchInfo _error; public HttpRequestPipeReader() { @@ -92,7 +92,10 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http if (_state != HttpStreamState.Closed) { _state = HttpStreamState.Aborted; - _error = error; + if (error != null) + { + _error = ExceptionDispatchInfo.Capture(error); + } } } @@ -112,7 +115,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http { if (_error != null) { - ExceptionDispatchInfo.Capture(_error).Throw(); + _error.Throw(); } else {