While going from Paused to Stopped, the Service Hangs at Stopping
-
While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }
-
While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }
-
While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }
I'm not even going to bother trying to read that unformatted code, but have you debugged it in the debugger? You can attach to service processes and step through and use breakpoints...
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
While going from Paused to Stopped the Service Status Hangs at Stopping, eventually timing out and receiving an error message. Error 1053: The service did not respond to the start or control request in a timely fashion. Following code is causing the service to go into not responding state when going from paused to Stopped state. Can anyone plz help me in finding out whats wrong with the code? When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way? VOID Handler (DWORD controlCode) { DWORD currentState = 0; BOOL success; switch(controlCode) { // Stop the service case SERVICE_CONTROL_STOP: { success = SendStatusToSCM(SERVICE_STOP_PENDING, NO_ERROR, 0, 1, 5000); } break; // Pause the service case SERVICE_CONTROL_PAUSE: if (runningService && !pauseService) { // Tell the SCM what's happening success = SendStatusToSCM( SERVICE_PAUSE_PENDING, NO_ERROR, 0, 1, 1000); pauseService = TRUE; SuspendThread(threadHandle); currentState = SERVICE_PAUSED; } break; } BOOL SendStatusToSCM (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwServiceSpecificExitCode, DWORD dwCheckPoint, DWORD dwWaitHint) { BOOL success; SERVICE_STATUS serviceStatus; // Fill in all of the SERVICE_STATUS fields serviceStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS; serviceStatus.dwCurrentState = dwCurrentState; // If in the process of doing something, then accept // no control events, else accept anything if (dwCurrentState == SERVICE_START_PENDING) serviceStatus.dwControlsAccepted = 0; else serviceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_PAUSE_CONTINUE | SERVICE_ACCEPT_SHUTDOWN; // if a specific exit code is defined, set up // the win32 exit code properly if (dwServiceSpecificExitCode == 0) serviceStatus.dwWin32ExitCode = dwWin32ExitCode; else serviceStatus.dwWin32ExitCode = ERROR_SERVICE_SPECIFIC_ERROR; serviceStatus.dwServiceSpecificExitCode = dwServiceSpecificExitCode; serviceStatus.dwCheckPoint = dwCheckPoint; serviceStatus.dwWaitHint = dwWaitHint; // Pass the status record to the SCM success = SetServiceStatus (serviceStatusHandle, &serviceStatus); return success; }
SunilKrSingh wrote:
When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way?
No. Those two values are intended for different usages. I am not sure how you decided they were equivalent. You use SERVICE_STOP_PENDING, while you are doing work to stop a service. Such as if you have a thread that you must wait to complet. You need to use the value SERVICE_STOPPED when the service is stopped. Just before you exit. And the reason it appears to work is because SERVICE_CONTROL_STOP and SERVICE_STOPPED both resolve to the same integer value.
-
SunilKrSingh wrote:
When I use SERVICE_CONTROL_STOP instead of SERVICE_STOP_PENDING in the method SendStatusToSCM, it resolves the issue. Is this correct way?
No. Those two values are intended for different usages. I am not sure how you decided they were equivalent. You use SERVICE_STOP_PENDING, while you are doing work to stop a service. Such as if you have a thread that you must wait to complet. You need to use the value SERVICE_STOPPED when the service is stopped. Just before you exit. And the reason it appears to work is because SERVICE_CONTROL_STOP and SERVICE_STOPPED both resolve to the same integer value.
I got the root cause of the issue. Pausing the service is causing the service thread to be suspended with the statement SuspendThread(threadHandle); So an attempt to stop the service from a paused state with SERVICE_STOP_PENDING was failing with error Error 1053: The service did not respond to the start or control request in a timely fashion. I had to resume the service thread before the stopping the service. Thanks, Sunil