Hi Sergey,
I’ve encountered very interesting behavior where after initiating service shutdown, SCM reports service as stopped, while the process is kept running in the background.
When attached to process in VS, in Debug->Threads window, I’m seeing Hangfire and Hangfire.Redis-related threads running in the background.
I’m using DI container (Ninject) which handles calls to dispose methods.
Before that, I’m triggering server.SendStop method, I even tried with WaitForShutdownAsync (with cancellation token) and explicit dispose. Nothing helped.
Furthermore, I’ve tried disposing of the storage-connection manually, but that didn’t help either.
I’m seeing correct log entries:
Execution loop Worker:c3177f68 stopped in 0 ms
Server xxxx:37352:3511c942 is reporting itself as stopped
Server xxxx:37352:3511c942 has been stopped in total 253.0794 ms
I’ve completely ditched my business logic from (commented out scheduled task and relevant logic) and this still happens.
Only thing that helps is calling Environment.Exit method after DI container finishes its shutdown process.
If I don’t call Environment.Exit, process shuts down itself after about ~10 minutes (haven’t measured)
Hangfire.Core 1.7.9
Hangfire.Pro 2.2.3
Hangfire.Pro.Redis 2.8.3
Hangfire.Ninject 1.2.0
Fun fact is that this doesn’t happen in completely different windows service with different tasks. I’ve compared line by line and haven’t figured it out. Same build target, same boilerplate code for startup and shutdown.
Any ideas/suggestions appreciated. Thanks.