BlueMonkMN
BlueMonkMN

Reputation: 25601

Windows Service Hung on Starting during boot

We have two services developed in Visual Studio .NET 2008 with VB.NET. Both were developed completely separately by separate individuals (one of them being myself), but both are reporting the same error during boot: "service hung on starting" appears in the System event log after booting. The services proceed to start up fine after that message (just a few messages down the line is the notice that the service started). Is there something about the slowness of loading the .NET framework or JIT compiling the code that's causing this or what? It starts and stops fine when done manually. Mine is a very simple service with no startup code other than that provided by the framework.

Update 1: This is all I've got in OnStart:

  host = New ServiceHost(GetType(FSE.Licensing.FSELicense))
  host.Open()

FSELicense does not define a constructor, so it just gets the default empty public constructor provided by VB.NET, I guess.

Update 2: My question has morphed based on the solution proposed by a colleague which supposedly fixed the problem. This solution does in fact simply add a dependency on another service that I did not think was necessary since my service does not do anything until a request is made of it. However, it does declare a variable of a COM type. Is it possible that having a reference to this COM type (even though there is no instance) will cause the COM DLL to load at the same time as the service, and possibly rely on a service? I didn't realize COM references were like static links in .NET if so.

Upvotes: 3

Views: 7458

Answers (4)

Klaus Schüssler
Klaus Schüssler

Reputation: 21

Adding a dependency on HTTPFilter sometimes solves the problem for us. We've used this workaround for some windows server 2008 systems. This HTTPFilter service doesn't seem to be installed on some Windows 7 Professional 64bit systems, which will then actually caused for the problem that the wcf service host doesnt start(cannot find the dependency).

Upvotes: 1

oefe
oefe

Reputation: 19916

Try to minimize the processing in OnStart; in particular, avoid blocking for an unknown amount of time; e.g. don't try to connect remote computers -- no database queries, no service requests.

If you need to do something that might block or otherwise take a long time, spawn a separate thread for this task if possible.

However, you cannot always avoid blocking completely, as you need to make sure that your services is operational when you return from OnStart. In such cases, you can use ServiceBase.RequestAdditionalTime to request more time for OnStart to finish.

Upvotes: 2

Scott Fletcher
Scott Fletcher

Reputation: 1487

I solved my problem by adding a service dependency to the service for "HTTP SSL service" (HTTPFilter). I had the exact same problem on an XP machine with a Windows Service that I wrote in .NET that exposed a WCF endpoint with a netpipe and http binding. When the system started up, it would always hang on the host.Open() call, and eventually timeout. I could start the service manually with no problem.

See this link for instructions on adding a service dependency. The DependOnService value that I used was HTTPFilter

Upvotes: 4

David
David

Reputation: 73574

This is a guess, but during system startup, so many things are loading behind the scenes that this slows things down already.

Then you also have to worry about components that rely on other services to be started. For example, if your service relied on the SQL Server Agent, which relies on the SQL Server Database Engine services, you'd have to wait for the to load in the order of the dependencies.

So...

Depending on what FSE.Licensing.FSELicense does internally, it may be waiting for other services that it depends on to load first, or it could just be that the machine is slow, and loading all of the background processes is happening at the same time and your service is simply competing for resources with all of those processes.

However, the warning you're seeing i just a warning. I've seen this on some of my services that can take a while to load. This is obvious and I probably don't even need to say it, but the service control manager expects services to load within a specific time period (I'm not sure what that is) but if a service appears to hang, it logs this message but in the meantime, the service is still trying to load. As long as your service is starting, I wouldn't worry too much about this warning, unless you can see some way to code it better to avoid this.

One thing you could check is in the Services console, look at the properties of your service and look at the "Dependencies" tab. it may be blank, but it may give you some insight.

Upvotes: 0

Related Questions