Skip to content

0.5% customers will fail to Start my App when run as Windows Service #77327

Open
@mingtong

Description

@mingtong

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

OS: 10.0.19044.0, 10.0.19043.0, 10.0.22000.0
.net: 6.0.4 (self container)
For short, my App have around 3m live users per day, now about 15k users per day report error log with the folloing.

System.InvalidOperationException: Stopped without starting
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)

My starting code is like

            IHost host = CreateHostBuilder(argsWithoutConsole, hostIP, hostPort).Build();
            await host.StartAsync().ConfigureAwait(false);
        private static IHostBuilder CreateHostBuilder(string[] args, string hostIP, int hostPort)
        {
            var ipAddress = hostIP;
            int availablePort = hostPort;

            var builder = Host.CreateDefaultBuilder(args);

            if (!ServiceUtil.IsRunningAsAdministrator())
            {
                logger.Debug("Is Running As service");
                builder.UseWindowsService();
            }
            builder.ConfigureHostOptions(config =>
                       {
                           //config.ShutdownTimeout = TimeSpan.FromSeconds(5);
                       })
                       .UseServiceProviderFactory<ContainerBuilder>(new AutofacServiceProviderFactory())
                       .ConfigureWebHost(webBuilder =>
                       {
                           webBuilder
                               .UseStartup<ServiceConfig>()
                               .UseKestrel((hostingContext, options) =>
                               {
                                   options.Listen(IPAddress.Parse(ipAddress), availablePort);
                               });
                       });

            return builder;
        }

what will be the probable reason for this?
Since the exception is just kind of easy, so I cant find useful information of the "Stopped without starting".

Expected Behavior

No response

Steps To Reproduce

It happened to customers only, so there is no clear steps to reproduce, that is also why I am posting here.

Exceptions (if any)

System.InvalidOperationException: Stopped without starting
at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)

.NET Version

6.0.4

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions