go: x/sys/windows/svc: the service terminated unexpectedly (id 7034)
What version of Go are you using (go version)?
$ go version go version go1.14.4 windows/amd64
Does this issue reproduce with the latest release?
Yes. Go version: go1.14.4 x/sys version: v0.0.0-20200625212154-ddb9806d33ae
What operating system and processor architecture are you using (go env)?
go env Output
$ go env set GO111MODULE= set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\alex\AppData\Local\go-build set GOENV=C:\Users\alex\AppData\Roaming\go\env set GOEXE=.exe set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GONOPROXY= set GONOSUMDB=* set GOOS=windows set GOPATH=C:\Users\alex\go set GOPRIVATE= set GOPROXY=https://proxy.golang.org,direct set GOROOT=c:\go set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=c:\go\pkg\tool\windows_amd64 set GCCGO=gccgo set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=E:\WorkGo\src\golang.org\x\sys\go.mod set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\A6473~1.POG\AppData\Local\Temp\go-build406331230=/tmp/go-build -gno-record-gcc-switches GOROOT/bin/go version: go version go1.14.4 windows/amd64 GOROOT/bin/go tool compile -V: compile version go1.14.4 gdb --version: GNU gdb (GDB) 7.9.1
What did you do?
Problem: Building a windows service using x/sys/windows/svc on go1.14+ will cause a service to terminate unexpectedly on system shutdown (SERVICE_CONTROL_SHUTDOWN command).
How to reproduce: Build a default example for x/sys/windows/svc on go1.13 and go1.14. The latter will be terminated unexpectedly and produce a corresponding event in the event log (7034), while the former one will stop just fine.
Remarks:
- A service can be stopped and started via service manager without an issue, the problem occurs on system shutdown or reboot.
- Reverting x/sys/windows/svc to initial commits does nothing, i.e. the problem, probably, somewhere in-between go1.13 and go1.14. go_svc_7034.zip
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 16 (5 by maintainers)
Commits related to this issue
- [release-branch.go1.15] runtime: detect services in signal handler The service handler needs to handle CTRL+C-like events -- including those sent by the service manager itself -- using the default Wi... — committed to golang/go by zx2c4 4 years ago
- [release-branch.go1.14] runtime: detect services in signal handler The service handler needs to handle CTRL+C-like events -- including those sent by the service manager itself -- using the default Wi... — committed to golang/go by zx2c4 4 years ago
@aclements
This issue is with golang.org/x/sys/windows/svc package.
The problem was introduced in
https://go-review.googlesource.com/c/go/+/187739/
After the CL 187739, every Windows service would not receive “shutdown” event. When computer is shutdown, Go service just exits, instead of handling “shutdown” event.
@zx2c4 sent a fix for this issue
https://golang.org/cl/242280
And the fix is in runtime package.
Both Jason and I think the fix should be back-ported to Go 1.14 (Go 1.13 is good). Should we submit CL 242280 now? Should we wait for tree to be opened first? Do you agree CL 242280 should be back-ported?
There is some risk involved. Here, in particular, we don’t even have a test for the fix - you need to reboot computer to test our fix.
What do you think?
Thank you.
Alex