Skip to content

Detecting IIS 503s caused by multiple host instances #48457

@Tratcher

Description

@Tratcher

https://techcommunity.microsoft.com/t5/iis-support-blog/asp-net-core-503-server-has-been-shutdown/ba-p/3830338

In IIS in-proc, if a developer creates and disposes an extra host for some reason before creating the real host they intend to start, the disposal of the first host puts IIS in a faulted state that the second one can't recover from. This results in the app returning 503s after the first few requests.

We should see if it's feasible to detect this state when starting the second host and at least produce a good error. e.g. "IIS can't be started because something in the process has already shut it down. Remove any extra Hosts."

public static void Main(string[] args)
{
    WebHost.CreateDefaultBuilder(args).UseStartup<EnvironmentStartup>().Build()
        .Dispose();
    CreateHostBuilder(args, EnvironmentStartup.Configuration).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args, IConfiguration config)
{
    return Host.CreateDefaultBuilder(args).ConfigureAppConfiguration(delegate(HostBuilderContext hostingContext, IConfigurationBuilder config)
    {
        [truncated]
    }).ConfigureWebHostDefaults(delegate(IWebHostBuilder webBuilder)
    {
        if (config.GetValue<bool>("UseIISHosting"))
        {
            webBuilder.UseIIS();
        }
        else
        {
            webBuilder.UseKestrel();
        }
        webBuilder.UseStartup<Startup>();
    });
}

Metadata

Metadata

Assignees

Labels

area-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsbugThis issue describes a behavior which is not expected - a bug.feature-iisIncludes: IIS, ANCM

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions