aspnet / AspNetKatana

Microsoft's OWIN implementation, the Katana project
Apache License 2.0
960 stars 331 forks source link

Client disconnects, requests keep running #449

Closed elangelo closed 8 months ago

elangelo commented 2 years ago

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.

Tratcher commented 2 years ago

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?

elangelo commented 2 years ago

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.

Tratcher commented 2 years ago

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