The Core Technologies Blog

Professional Software for Windows Services / 24×7 Operation


Service Protector Feature Spotlight: Restart A Stuck Service

Restart Stuck Services

Why should Service Protector restart a service that’s stuck starting or stopping?

When a Windows Service is in the “Starting” or “Stopping” status, it’s probably not be doing its work. For all intents and purposes, your service may be down during those periods.

Usually that’s not a problem though, because services typically move through those transitory states very quickly. In our experience, a service isn’t in the starting or stopping state for longer than a couple of seconds — while it opens network connections, connects to a database, shuts down cleanly or performs another important one-time task.

But there are unfortunate occasions where a service takes too long to start or stop. And in those situations, the only cure is to forcibly terminate and restart the service.

As part of its mission to keep your Windows Service running 24/7, Service Protector has code to automatically detect and terminate a stuck service. We recommend activating that feature if you’re managing a service that has trouble moving in or out of the running state quickly.


How do I activate the feature in Service Protector?

When adding (or editing) your service, you can instruct Service Protector to deal with the stuck states on the Extras tab:

Enable stuck service protection

With the settings in the screenshot above, Service Protector will terminate and restart your service if it lingers in the “Starting” or “Stopping” state for longer than a minute.

In our experience, 60 seconds is about right for most services. Under normal situations, it’s rare for a Windows Service to take much more time as it starts or stops.


What are your best tips for handling stuck services?

Tip #1: Adjust the timeouts for your service

While the default timeout of 60 seconds will suit most customers’ needs, every Windows Service is unique. As such, you should definitely tune the timeouts for your specific situation.

For instance, if your service takes a while to initialize — perhaps because it has to negotiate complex operations in a distributed environment — you should increase the starting timeout to compensate.

Tip #2: Setup email alerts to identify “flapping”

With this feature in place, Service Protector will automatically restart your service whenever it gets stuck for too long. Usually that timely restart is enough to get things moving again.

But sometimes restarting isn’t the answer. We’ve seen situations where the service simply got stuck again and repeatedly restarting did no good. Manual intervention was required.

We recommend setting up email alerts to help you detect edge-case situations like that. That way, if you see Service Protector continuously restarting your stuck service, you can jump in to save the day.


Posted in Service Protector | Tagged , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *