-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/sys/windows/svc/example: does not start #40160
Comments
/cc @alexbrainman @bradfitz per owners. |
@macklin-10x thank you for reporting this issue, but I cannot reproduce it here. I am using this commit
with this go version
and I use this version of Windows What do you use? Thank you. Alex |
Well, to make the issue even stranger: if I configure the service to start automatically and reboot the machine, the service starts on boot and runs correctly. If I then stop the service and start it again, it fails to start with the aforementioned error. I'm beginning to think this is some obscure issue with Windows rather than anything in the go source. |
I am not convinced it is some Windows problem. For example, we have #23479 where people report random problems. It could be bug in Go code. If you can reproduce the problem, please, try to understand where the problem is. Unfortunately, it is not easy to debug Go service. The only way I know is by adding source lines to log into Event Log. I doubt you could use debugger, because service is meant to act on events within a 30 seconds or something. Also, if service process crashes, I do not know of a away to tell service manager about it, so you would have to reboot computer. There is also #40074 - but that bug is about shutdown event - which is different from what you describe. Sorry I could not be more helpfull. Alex |
Since I've already got the example building, I'll try adding a bunch of debug print statements and see if I can uncover a root cause. It's rather confusing as I already adding at least a top-level panic handler and it isn't catching a panic. |
I logged the execution path all the way down to a call to
The arguments passed to Just below the call to I'm not sure if this is because the syscalls are never returning or for some reason the whole process is getting torn down before they have a chance to return. I added panic loggers to both goroutines but neither seem to be panicking. |
Please, try do that. Maybe we can solve #40074 .
I am not sure what do you mean by that. But I would not be surprised that panic does not work in some situations - we are too low level. Maybe just add log statements, and log to either file or Windows Event Log.
This is first line in
StartServiceCtrlDispatcher is not meant to return. It will return when service ends, or if there is an error configuring service. Perhaps there is a bug in servicemain in sys_amd64.s. Mind you I am not sure how to debug it. Maybe call some print function from servicemain ? Perhaps @zx2c4 has some ideas on how to debug this. Alex |
Any further input on how to debug this? All of our Windows systems reproduce this bug reliably. |
I'm waiting to see more apt panics, by following what Alex suggested. Do the usual recover block, but write to a file or event log, so that you can retrieve a log and a stacktrace. If that fails, attach a debugger so that crashes at least result in a break and you can inspect the crashing thread. |
I already added blocks that recover a panic, write it to the event log, and repanic at the top of every goroutine invocation, and haven't observed output from any of them. I don't understand how to attach a debugger to the process started by the service manager. |
It just shows that none of your goroutine panics. But you might have code blocked in syscall, your code might crash without panic. I would suggest add logging statement all over you code, starting from the start of your program and continue until you find where your program crashes or blocks or whatever. We normally do this with println or fmt.Prtintf. But, because it is a service, you cannot output to standard output. So make your logging function write to a disk file or to Windows Event log. Perhaps even close file after every write to make sure there are no unsaved changes to be lost, if process crashes or something.
Unfortunately I don't know how to use debuggers. Especially debugger with Windows service program. You can see some instructions of me using WinDbg #36492. But WinDbg will not print Go symbols. For that you need to sue Delve debugger. Delve provides command line flag to pass PID to attach to a running process. Perhaps @zx2c4 might give some debugging suggestions. But I would try to log things first. If you can reproduce the problem easily, you should be able to point exact place in the program where things go wrong. Then we might be able to guess where the bug is. Thank you. Alex |
Just attach to the service PID with windbg, and then immediately press "continue". If you find the service is crashing too soon, insert 10 second sleep between the process startup and the call to the start the service control. During those 10 seconds, attach windbg to the PID. |
I've been helping @macklin-10x with debugging this on the test machine, and my current best guess about what is going on is that this is a bad interaction between the go runtime and something being injected into the process by some malware monitoring software. I probably won't have a chance to work on this more today but will update this further if I can get more detail on what's going on there. Obviously, from a certain perspective, if AV is breaking things by forcibly injecting its own threads into the process that isn't exactly Go's fault, but on the other hand there may be something simple that can be done to mitigate the issue, given that AV of some kind is standard practice on Windows. |
Change https://golang.org/cl/246317 mentions this issue: |
@macklin-10x and @adam-azarchs can you, please, try this change Does it help with your problem? Thank you. Alex |
With this patch the example service runs correctly without bypassing our antivirus software! |
Thanks for checking. I just submitted the change. Alex |
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?
What did you expect to see?
From the
debug
invocation, beeping and logging to the command line.From the
start
invocation, the service starts, beeps periodically, and logs "beep" at info level to the event log.What did you see instead?
The
debug
invocation runs correctly, logs to the command line, and beeps.The
start
invocation returns no error, but the service fails to start."starting myservice service" is logged to the Application event log at info level.
"The my service service terminated unexpectedly." is logged to the System event log at error level.
Trying to start the service from the GUI service manager provides the same error.
The text was updated successfully, but these errors were encountered: