Recycling Isn’t Always Good

Know the Gotchas of automatic ASP.NET restarts.

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 make it as robust as possible while maximizing performance. For the most part they succeeded beyond all expectations with those goals, particularly when you compare it to "ASP.old." But with any complex feature there are plenty of gotchas 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 that grabbed all the processing cycles in a thread or that froze up ASP, your Web site was pretty much hosed for the duration, until someone noticed it and restarted IIS (or Windows). ASP.NET fixes this problem, in accordance with the goal of making it robust, by automatically restarting the ASP.NET application under various circumstances, such as code in a page that takes too long to run.

 

According to the documentation, ASP.NET will also restart the entire system when any of the following occur:

  • Modification of machine.config, web.config, or global.asax
  • Modification of the application's bin directory or its contents
  • When the number of compilations (ASPX, ASCX, or ASAX) exceeds the limit specified by <compilation numRecompilesBeforeAppRestart=/>
  • Modification of the physical path of a virtual directory
  • Modification of the code-access security policy
  • The w3svc Windows service is restarted

 

You can monitor restarts using the ASP.NET Application Restarts performance counter in the Windows Performance Monitor tool.

 

So this is a Good Thing, right? Yes, it certainly is. But it can also cause some problems in some very unexpected ways. These have come to light during discussions on the Microsoft-sponsored http://www.asp.net forums. Members would post messages about weird problems with their ASP.NET applications losing session variable values and other session-related state. After we ask the usual questions to explore problems with session timeouts and related issues, inevitably someone asks about server restarts. The usual response is that the server hasn't been rebooted in days (weeks/months/years). But then the person goes in and monitors ASP.NET restarts only to find that they are happening many times a day. Problem solved, even if resolving it may still take a lot of work.

 

There are several side effects of these restarts, but none desirable. You lose session state, including all session variables. Not good if someone has $5,000 worth of purchases in a shopping cart that you maintain in session state. The HttpApplication object's Start and End events fire for every restart, potentially leading to various travesties, depending on what code you put there. At best, you get some incorrect usage monitoring results.

 

The moral is that when you start getting weird problems like those I've talked about here, check for ASP.NET restarts. They might lie at the root of all your troubles.

 

Resources

Here are a few Microsoft KnowledgeBase (http://support.microsoft.com/) articles to acquaint you with the issues:

 

Don Kiely is senior technology consultant for Information Insights, a business and technology consultancy in Fairbanks, Alaska. E-mail him at mailto:[email protected].

 

 

 

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish