Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preshutdown timeout not work #1085

Open
T-TianXIn opened this issue May 6, 2024 · 0 comments
Open

Preshutdown timeout not work #1085

T-TianXIn opened this issue May 6, 2024 · 0 comments
Labels

Comments

@T-TianXIn
Copy link

I've already enable the preshutdown feature and set the preshutdown timeout to 10min. But whenever I restart the system, service will be forcibly killed by system in 2min. It seems that preshutdown timeout does not take effect.

Steps to reproduce

I use a simple service to reproduce this issue. The program will sleep forever when receive the CTRL C signal. The config file is like that:

<service>
  <id>MyService</id>
  <name>My Sample Service</name>
  <description>This service is a simple test example.</description>
  <executable>D:\project\winsw-test\x64\Release\winsw-test.exe</executable>
  <logmode>rotate</logmode>
  <stoptimeout>5 min</stoptimeout>
  <preshutdown>true</preshutdown>
  <preshutdownTimeout>10 min</preshutdownTimeout>
</service>

When I stop the service normally, it will be killed by winsw and exited:

2024-04-18T17:53:32.010 INFO  console - Stopping service 'My Sample Service (MyService)'...
2024-04-18T17:53:32.040 INFO  service - Stopping MyService
2024-04-18T17:53:32.042 DEBUG service - ProcessKill 6560
2024-04-18T17:58:31.579 INFO  service - Child process 'winsw-test (6560)' terminated.
2024-04-18T17:58:31.599 INFO  service - Finished MyService
2024-04-18T17:58:31.599 INFO  service - Service stopped successfully.
2024-04-18T17:58:31.699 INFO  console - Service 'My Sample Service (MyService)' stopped successfully.

But when I restart the system, it will not be killed by winsw. It seems like that winsw is forcibly killed by system and does not have time to send CTRL C signal to my test program:

2024-04-18T17:59:48.285 INFO  service - Stopping MyService
2024-04-18T17:59:48.288 DEBUG service - ProcessKill 9912
2024-04-18T18:03:11.355 DEBUG console - Starting WinSW in service mode.
2024-04-18T18:03:11.418 INFO  service - Starting D:\project\winsw-test\x64\Release\winsw-test.exe
2024-04-18T18:03:11.477 INFO  service - Started process winsw-test (7712).
2024-04-18T18:03:11.505 INFO  service - Service started successfully.

Check the Windows event log, also find an error for SCM service did not shutdown properly after receiving a preshutdown control(also see this error in #614)

Environment

  • WinSW version: v3.0.0-alpha.11
  • WinSW package type: x64
  • Windows version: Windows 10 19041

Possible Solution

According to this doc https://learn.microsoft.com/en-us/archive/msdn-magazine/2008/launch/windows-with-c-windows-services-enhancements, service must update checkpoint value when preshutdown:

image

I check the winsw source code and find out that winsw doesn't update the checkpoint value when stopping the service. So I try to add a new thread to increase the checkpoint value every 30s during service stopping based on https://github.com/winsw/winsw/tree/v3.0.0-alpha.11. Using the fixed winsw, the issue is gone.

@T-TianXIn T-TianXIn added the bug label May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant