Skip to content

Kestrel execution timeout support #10079

Closed
@effyteva

Description

@effyteva

Hi,

We've been facing some high CPU issues on our ASP.NET core 2.2 production environment for the past few weeks. The only way to "revive" our instances, was to restart Kestrel (or the server instance of course).
Following some hard time, we ended up finding some very rare scenario, in which our application was going through an infinite loop, which Kestrel never stopped processing.
This means any single request hitting this bug, created a 100% CPU usage task on our server instance, which never goes away...

We tried using the "RequestTimeout" setting on web.config (after switching to OutOfProcess hosting model), which returned an error to the client ("The specified CGI application encountered an error and the server terminated the process"), however, the server kept processing the request infinitely.

I believe the ExecutionTimeout which never made it to Kestrel on ASP.NET core might be a good solution for error handling on the server level.
For additional regarding ExecutionTimeout information, please see @Tratcher and @benaadams review and remarks here: aspnet/KestrelHttpServer#485, aspnet/KestrelHttpServer#611.

To re-produce the issue, a simple "while (true)" should be called during the request processing. We placed it on the view for simplicity.

Obviously all of our code is using the RequestAborted cancellation token when possible, yet in the case we mentioned, we had a complex code which shouldn't have been a long running CPU task, but ended up acting as an infinite loop.

We also tried creating a Middleware for limited the execution time, it didn't much good either, as we couldn't a way to "kill" the running task. Perhaps it could be done?

Tagging for future documentation purposes: dotnet/AspNetCore.Docs#12330

Thank you,
Effy

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions