Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Owin on IIS web requests hang indefinitely

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: Requests hang in IIS manager 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

like image 957
Vidar Kongsli Avatar asked Oct 21 '15 10:10

Vidar Kongsli


1 Answers

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.

like image 130
Vidar Kongsli Avatar answered Oct 03 '22 09:10

Vidar Kongsli