Recycling Isn’t Always Good
Know the Gotchas of automatic ASP.NET restarts.
October 30, 2009
Troubleshooting Tips
LANGUAGES: All .NET Languages
ASP.NET VERSIONS: 1.0 | 1.1
Recycling Isn't Always Good
Know the Gotchas of automatic ASP.NET restarts.
By Don Kiely
One of Microsoft's primary goals with ASP.NET was to makeit as robust as possible while maximizing performance. For the most part theysucceeded beyond all expectations with those goals, particularly when youcompare it to "ASP.old." But with any complex feature there are plenty ofgotchas that can trip you up, making for some weird troubleshooting sessions.One of the best examples of this is ASP.NET recycling.
In "ASP.old" applications, if something happened thatgrabbed all the processing cycles in a thread or that froze up ASP, your Website was pretty much hosed for the duration, until someone noticed it andrestarted IIS (or Windows). ASP.NET fixes this problem, in accordance with thegoal of making it robust, by automatically restarting the ASP.NET applicationunder various circumstances, such as code in a page that takes too long to run.
According to the documentation, ASP.NET will also restartthe entire system when any of the following occur:
Modification of machine.config, web.config, orglobal.asax
Modification of the application's bin directory or itscontents
When the number of compilations (ASPX, ASCX, or ASAX)exceeds the limit specified by
Modification of the physical path of a virtualdirectory
Modification of the code-access security policy
The w3svc Windows service is restarted
You can monitor restarts using the ASP.NET ApplicationRestarts performance counter in the Windows Performance Monitor tool.
So this is a Good Thing, right? Yes, it certainly is. Butit can also cause some problems in some very unexpected ways. These have cometo light during discussions on the Microsoft-sponsored http://www.asp.net forums. Members would postmessages about weird problems with their ASP.NET applications losing sessionvariable values and other session-related state. After we ask the usualquestions to explore problems with session timeouts and related issues,inevitably someone asks about server restarts. The usual response is that theserver hasn't been rebooted in days (weeks/months/years). But then the persongoes in and monitors ASP.NET restarts only to find that they are happening manytimes a day. Problem solved, even if resolving it may still take a lot of work.
There are several side effects of these restarts, but nonedesirable. You lose session state, including all session variables. Not good ifsomeone has $5,000 worth of purchases in a shopping cart that you maintain insession state. The HttpApplication object's Start and End events fire for everyrestart, potentially leading to various travesties, depending on what code youput there. At best, you get some incorrect usage monitoring results.
The moral is that when you start getting weird problemslike those I've talked about here, check for ASP.NET restarts. They might lieat the root of all your troubles.
Resources
Here are a few Microsoft KnowledgeBase (http://support.microsoft.com/)articles to acquaint you with the issues:
KB 316148: PRB: "SessionVariables Are Lost Intermittently in ASP.NET Applications"
KB 319947: BUG: "MultipleASP.NET Application Restarts Occur Every One to Five Minutes"
Don Kiely is seniortechnology consultant for Information Insights, a business and technologyconsultancy in Fairbanks, Alaska. E-mail him at mailto:[email protected].
About the Author
You May Also Like