Skip to content

AspNetCoreModuleV2 should be able to restart executable if startup fails #47432

Closed
@AnkHansen

Description

@AnkHansen

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am hosting our .Net 6.0 API on IIS on Windows server using the AspNetCoreModuleV2 handler.

During startup, we need to connect to a SQL server to load some customer specific configuration details.

If the SQL server is unavailable at the time the API starts, it throws an unhandled exception, and the executable exits.

This works fine when using Kestrel and running from command prompt.

When executed in IIS, it seems like the AspNetCoreModuleV2 handler tries to start the executable, it crashes, and the handles returns 500 - which is fair as it crashes.

But the handler then stays in this state, and never seems to try and restart the executable.

The restart logic must be there anyway as it can handle the process crashing later on, so seems like a flag that detects that it is during initialization it fails - and then it is decided to not retry.

If the executable crashes (or manually killed) later on after startup sequence is completed the AspNetCoreModuleV2 successfully boots a new instance of the executable.

Best regards
/Anders

Describe the solution you'd like

I would like a feature where it would be possible to configure how to handle startup errors.

In our case it happens rarely, but is 99% of the time due to the API is starting in a SQL server service window, connection failure or similar. And then we manually have to go through all API's and restart these in the faulty state. (or by scripting).

I am aware of the problems that can arise if 100's, 1000's or more requests hits the IIS - and all instances keeps crashing.

So maybe something about a window in which it keeps returning 500 for e.g. 1, 2, 5 minutes - and then tries to restart an instance of the executable again, so we don't try to restart every second - but only a few times an hour.

<aspNetCore processPath=".\myApi.exe" hostingModel="outofprocess" startupFailureWindow="00:05:00"/>

The name of the attribute is obviously up to you to decide so it matches convention of other attributes.

Additional context

Have posted the question on StackOverflow with no good result: https://stackoverflow.com/questions/75578644/how-to-handle-if-asp-net-core-api-crashed-during-building-host/75589373?noredirect=1#comment133379495_75589373

From our investigations a reproduction of the issue would just need an API that in Startup.cs throws an exception, and then using it in IIS using web.config ith AspNetCoreModuleV2.

Metadata

Metadata

Assignees

Labels

✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-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