tags:

views:

377

answers:

2

Hi All,

I have a webservice on one of my websites which restarts the websites app pool.

The problem Im getting is the IIS7 app pool keeps stopping with the following warning and then error:

Warning: A process serving application pool 'appPoolNameHere' exceeded time limits during shut down.

Error: Application pool 'appPoolNameHere' is being automatically disabled due to a series of failures in the process(es) serving that application pool.

The code I am using to do this is:

            try
        {

            var serverManager = new ServerManager();

            var currentPoolName = SettingsManager.AppPoolName;

            if (!string.IsNullOrEmpty(currentPoolName))
                serverManager.ApplicationPools[currentPoolName].Recycle();

            HttpRuntime.Close();
        }
        catch (Exception ex)
        {                
            var exceptionManager = ExceptionManagerFactory.GetExceptionManager();
            exceptionManager.LogException(ExceptionManager.Severities.Critical, ex,
                                          "App Pool restart failed");
        }

I am not getting any exceptions being thrown here, but the app pool is stopping, this doesnt happen all the time and is very hard to replicate, I have tried several different things even just hitting the hell out of that service and sometimes its fine other times it dies.

Is there anything I can do to fix this?

The reason I have to restart it is due to an external config file to the webconfig which deals with the url redirects which is updated from the admin system.

Thanks for any help with this.

A: 

Well I seem to have sorted (not fixed) the issue, with some tape and sticky-back-plastic.

The solution

Changed app pool setting: Rapid-Fail Protection to false

This stops IIS from killing the app pool after several failed requests to it.

I also added in retry system, so if the recycle request fails it waits for 10secs and tries again, it will do this 5 times before giving up and sending out an exception notice.

This has fixed the problem, and everything seems to be working well again, although something about this screams this is wrong!! at me.

Only if IIS would monitor other files in a website and restart the app pool when it saw a change.

JamesStuddart
A: 

I didn't work with Microsoft.Web.Administration namespace, but what about unloading application domain and sending request to your website so that to start application again?

Good example (2nd point) by Peter Bromberg how to do this.

Update.

Reading error stack

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()

I thought of most common reason: insufficient rights. All administrative actions require administrative rights. When code above is executed, which user account is impersonated? IUSR? Switch to any admin for that block and it should work without exception.

terR0Q
I think this is how you do it for IIS6, as there is no direct hook into IIS6 from .net
JamesStuddart
But why shouldn't this work on IIS7? I added update with one idea after reading error stack.
terR0Q