x/sys/windows/svc: does not handle shutdown gracefully #40157
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
go.mod
main.go
I've copied and modified the source code slightly from sys/windows/svc/example and put them all in one file to minimize the repro.
Windows services has a number of events that are processed in a loop. These need to be handled gracefully, otherwise Windows will mark the service as not behaving appropriately and will prevent/throttle restarts.
The following are a few examples: stop, shutdown. When you receive a stop event or a shutdown event, you are expected to perform cleanup and stop the service. If this is not performed, Windows will kill the service.
In sys/windows/svc, these events are called svc.Stop and svc.Shutdown. In
main.go
, the event loop is calledloop
where these events are handled. All events seem to be handled correctly except for svc.Shutdown.Repro steps:
a)
svcshutdownbug.exe install
b)
svcshutdownbug.exe start
You should now have a service called myservice running. If you right click on it in the Task Manager and do "Restart", you should be able to find a few logged events in the Event Viewer under Windows Logs->Application. These are expected to be:
The above entries are correct and can be found under the Event ID "1337" and Source "myservice".
shutdown /s
Cleanup
Execute
svcshutdownbug.exe remove
to uninstall the serviceWhat did you expect to see?
What did you see instead?
Nothing is logged.
The process was terminated unexpectedly or killed by Windows due to not processing the svc.Shutdown event properly. This event is called
SERVICE_CONTROL_SHUTDOWN
in w32 lingo.The text was updated successfully, but these errors were encountered: