Susumu Arai
Susumu Arai

Reputation: 309

What causes StartServiceCtrlDispatcher() to fail with 1063 (ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)?

I'm seeing weird error with my Windows service program. My service program calls StartServiceCtrlDispatcher() at the very beginning of its main(), but it sometime fails with 1063 (ERROR_FAILED_SERVICE_CONTROLLER_CONNECT).

I know that this error occurs if the user starts program manually (as a console program). But, it's not the case. I added a code to check the parent process of the service program when this error occurs, and it tells services.exe is the parent process (I think it's safe to assume that my program was properly started by SCM).

Unfortunately, this error does not reproduce on my dev machine and cannot debug it by myself, but the error logs captured on user systems tells:

Has anyone seen similar error? If so, what was the cause of the error?

Upvotes: 15

Views: 35046

Answers (2)

hidalgo
hidalgo

Reputation: 1

TIP: I used _wfopen/fwrite/fclose to log some messages. Somehow 183 was thrown internally and was leading to this failure 1063. I removed logging and it started working normally as nothing happen. Any minute error may lead you to it. Start from services and it will list the wage error (183 in my case).

Upvotes: 0

Codeguard
Codeguard

Reputation: 7975

As you can already see from the absence of answers and anything on google, the problem isn't common. I believe the problem is in your service, AND it is in code executed from process's start to StartServiceCtrlDispatcher(), AND most likely it takes some form of corrupting system resources, likely heap or HANDLE's.

You can be sorry to hear this, but I'm not going to have a magic answer to your problems. Instead, I can suggest some troubleshooting.

Microsoft Application Verifier is invaluable in finding corruption. I suggest that you:

  1. Install it to your dev machine.
  2. Add your service's exe to it.
  3. Only select Basics\Heaps for the first time.
  4. Press Save. It doesn't matter if you keep application verifier open.
  5. Run your service a few times.
  6. If it crashes, debug it and the crash will point to your problem.
  7. If it doesn't crash, add Basics\Handles. Unlike Basics\Heaps, this can sometimes fire "false positives" - mistakes in code that doesn't hurt much. Anyway, since you're on the hunt, you'd better fix everything you can find. I'm mostly worried about double-freeing a HANDLE or something like that. Freeing a Service manager HANDLE by mistake can surely lead to your problem.
  8. If it still doesn't crash, you can try other options in Basics\*, but I don't think that will help.
  9. At this point, you might want to inspect the code between program's main() and StartServiceCtrlDispatcher(), and any global constructors you can have. Look for potential buffer overflows and errors with HANDLE's.
  10. The next step could be installing Application Verifier to the client's machine. There's not much harm in it, I sometimes do it when I can't find the error myself.

Upvotes: 8

Related Questions