microsoft / IIS.ServiceMonitor

An entrypoint process for running IIS in Windows containers
MIT License
126 stars 42 forks source link

Facing intermittent issues in windows container during startup #88

Open vipul0506 opened 10 months ago

vipul0506 commented 10 months ago

I'm currently running IIS app inside a windows container. These are the three last lines of my startup script: Invoke-Expression -Command "net start w3svc"; Invoke-Expression -Command "iisreset"; Invoke-Expression -Command "C:\\ServiceMonitor.exe w3svc" And here are the log trail from startup script:

Attempting stop...

Restart attempt failed.

The system cannot find the file specified. (2147942402, 80070002)

ERROR: Failed to stop or query status of service 'w3svc' error [800705b4]

I've reviewed the log trail for the startup script and It seems to be failed during on iisreset not sure if ServiceMonitor is contributing anything here. I can see this error was reported in the past - https://github.com/microsoft/IIS.ServiceMonitor/issues/49

Could you please confirm if this error has been fixed in the latest version of IIS.ServiceMonitor or provide guidance on how we can resolve this issue? Thank you for your assistance.

pankajads commented 6 months ago

Service Monitor stop and start the W3SVC. (here is the line of code that stop the W3SVC service https://github.com/microsoft/IIS.ServiceMonitor/blob/main/src/ServiceMonitor/Main.cpp#L47)

Also, it has timeout setting defined to start and stop service. Its W3SVC in your case and timeout setting set to 20 sec (hardcoded value). https://github.com/microsoft/IIS.ServiceMonitor/blob/main/src/ServiceMonitor/ServiceMonitor.h#L26-L28

There could be a instance where service mayn't complete stop or start in 20 sec and hence you will get the same error. You could increase timeout setting maxiumum to 30 sec, otherwise it gets timed out at OS level.

If you have very slow system, where service restart may take between 30-40 sec. I would recommend you to increase the OS setting (registry one to increase service start/stop timeout) along with service monitor timeout.

How to increase OS level service timeout?

  1. Click Start, click Run, type regedit, and then click OK.
  2. Locate and then click the following registry subkey:
    • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
  3. In the right pane, locate the ServicesPipeTimeout entry.

Note: If the ServicesPipeTimeout entry does not exist, you must create it. To do this, follow these steps: