AspNetKatana icon indicating copy to clipboard operation
AspNetKatana copied to clipboard

Client disconnects, requests keep running

Open elangelo opened this issue 4 years ago • 3 comments

We have an NGINX running in front of our owin iis hosted services. The NGINX is configured to disconnect if the owin service does not respond within 100 seconds. We can see these requests keep running after the client disconnected. I can even see requests that keep running for hours.

We are running the Owin stack version 4.1.1.

I have configured IIS to timeout the execution after 120 seconds. This doesn't seem to do anything <httpRuntime executionTimeout="120" />

I have tried to modify the TimeoutManager that is attached to the OwinHttpListener:

if (app.Properties.TryGetValue("Microsoft.Owin.Host.HttpListener.OwinHttpListener", out object listener))
{
    var l = listener as Microsoft.Owin.Host.HttpListener.OwinHttpListener;
    if (l != null)
    {
        // default queue length is 1000 (Http.sys default), lets increase it!
        //l.SetRequestQueueLimit(5000);
        // defaults to maxAccepts: 5 * Environment.ProcessorCount, maxRequests Int32.MaxValue
        //l.SetRequestProcessingLimits(256 * Environment.ProcessorCount, Int32.MaxValue);
        var tm = l.Listener.TimeoutManager;

        tm.IdleConnection = TimeSpan.FromSeconds(5);
        tm.MinSendBytesPerSecond = 100;

        Console.WriteLine(tm.IdleConnection);
    }
}

This doesn't do anything either.

elangelo avatar Mar 30 '22 10:03 elangelo

If you're using IIS then OwinHttpListener does not apply.

The Owin libraries do not control request lifetime in IIS, they only wrap the ASP.NET APIs.

IOwinRequest.CallCancelled can be checked by application code to see if the client has disconnected and cooperatively discontinue processing. I'm not aware of anything that can forcefully discontinue request processing. https://github.com/aspnet/AspNetKatana/blob/1afd57edc8c67c9e90f57dc02dee9eea7ab5f531/src/Microsoft.Owin/IOwinRequest.cs#L138

Did you capture a dump to see where the request was stuck?

Tratcher avatar Mar 30 '22 16:03 Tratcher

Does this change in anyway if we would be selfhosting? We are in the middle of moving off IIS... so if it would i might have to choose what scenario i'm trying to support.

elangelo avatar Mar 30 '22 17:03 elangelo

Not really. When self-hosting you are completely in control of the request lifetime at the application layer.

Tratcher avatar Mar 30 '22 17:03 Tratcher