runtime: 0.5% customers will fail to Start my App when run as Windows Service
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
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 22 (14 by maintainers)
Many thanks for your information, I will collect more logs in next release, and will update you here.
I root caused my particular issue and will file a separate dotnet bug with repro. Sneak preview: Was not related to SQLite, but rather a result of the
BackgroundService
extension not keeping the Windows SCM happy (e.g., cough, me not using the right WindowsServiceLifetimeOptions.ServiceName for its signals). I think similar errors in the SCM area will surface asStopped without starting
, which is a really poor/confusing developer experience.For background: I was also investigating SQLite’s bundler, which attempts to activate WinRT types and do appmodel things, all without explicitly checking for package identity. There’s a try/catch to cover the no-identity scenario, but it seems wrong to keep throwing exceptions that confuse developers during debug. I’ll file that bug too.
@mingtong My suggestion for your issue is to try getting Event logs from the affected customers (Application channel). Or at least a screenshot of the user attempting to start the service via Services. Either method should reveal the actual SCM error, which could aid in debugging further. (Mine was
The executable program that this service is configured to run in does not implement the service.
)I think you can log more information in the service so that you can get the failure details.