Owin on IIS web requests hang indefinitely

非 Y 不嫁゛ 提交于 2019-12-07 03:46:07

问题


We are running an Owin applications on IIS 8.5 on Win 2012 R2 behind a loadbalancer. One some occations, requests to certain URLs hang indefinitely. If the user selects cancel in the browser, and reloads the page, everything is OK and the server responds quickly.

In IIS manager, we can see the requests hanging: The hang seems to occur inside the Owin pipeline. We are running .NET 4.5.2 and the latest Owin packages.

Here's the code for the /api/whoami endpoint:

[Authorize]
public class WhoAmIController : ApiController
{
    [Route("whoami")]
    [HttpGet]
    public IHttpActionResult Whoami()
    {
        return Json(ClaimsPrincipal.Current.Identity.Name);
    }
}

An observation is that requests to this endpoint hangs in the AuthenticateRequest stage in the IIS pipeline, not PreExecuteRequestHandler which is the default IIS stage for the OWIN pipeline. Our only authentication method is cookie authentication, which executes in the AuthenticateRequest stage.

Any ideas?

Edit: adjusted screenshot


回答1:


The problem was that we had code executing on the IIS event PreSendRequestHeaders, which apperently is bad according to http://www.asp.net/aspnet/overview/web-development-best-practices/what-not-to-do-in-aspnet,-and-what-to-do-instead#presend

Our intention was to adjust HTTP headers on the way out on all request. The fix was to move the code to the BeginRequest event.




回答2:


Have you tried adding .ConfigureAwait(false) to your async calls?

Doing so will make the continuation continue on the "correct" thread.



来源:https://stackoverflow.com/questions/33256407/owin-on-iis-web-requests-hang-indefinitely

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!