Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

HttpContext disposed before the error code is set. #876

Closed
JunTaoLuo opened this issue May 24, 2016 · 2 comments
Closed

HttpContext disposed before the error code is set. #876

JunTaoLuo opened this issue May 24, 2016 · 2 comments
Assignees
Milestone

Comments

@JunTaoLuo
Copy link
Contributor

JunTaoLuo commented May 24, 2016

Currently in FrameOfT the HttpContext (https://github.com/aspnet/KestrelHttpServer/blob/dev/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs#L119) is disposed before ProduceEnd() is called (https://github.com/aspnet/KestrelHttpServer/blob/dev/src/Microsoft.AspNetCore.Server.Kestrel/Http/FrameOfT.cs#L133). Disposing of the HttpContext should only happen after Kestrel is really done with it, otherwise we can get into situations where the response on the HttpContext is not correctly set.

For example, we see in aspnet/Hosting#763 when logging the end of the request, the error code is not set correctly to 500:

fail: Microsoft.AspNetCore.Server.Kestrel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60[13]
      Connection id "0HKS2EAGK2HQR": An unhandled exception was thrown by the application.
System.ArgumentException: d
   at WebApplication2.Controllers.ValuesController.Get() in C:\Users\em\Documents\Visual Studio 2015\Projects\WebApplication2\src\WebApplication2\Controllers\ValuesController.cs:line 16
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeActionFilterAsync>d__41.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Internal.FilterActionInvoker.<InvokeAsync>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Mvc.Internal.MvcRouteHandler.<InvokeActionAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Builder.RouterMiddleware.<Invoke>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Hosting.Internal.RequestServicesContainerMiddleware.<Invoke>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Server.Kestrel.Http.Frame`1.<RequestProcessingAsync>d__2.MoveNext()
info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
      Request finished in 18.6067ms 200

cc @CesarBS @halter73

@halter73
Copy link
Member

@muratg What milestone should this be in? It seems mainly to lead 200 statuses in logs for 500 responses sent by Kestrel caused by uncaught exceptions thrown by the application. This is only an issue if the application hasn't written to the response body prior to throwing.

@muratg muratg added this to the 1.0.1 milestone May 26, 2016
@muratg
Copy link
Contributor

muratg commented May 26, 2016

I think we can get to this post RTM.

@muratg muratg assigned mikeharder and unassigned cesarblum Jul 8, 2016
@mikeharder mikeharder removed their assignment Jul 25, 2016
@muratg muratg modified the milestones: 1.1.0, 1.1.0-preview1 Oct 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants