How the Execution Timeout is managed in ASP.NET
As you are probably aware, it is possible to specify the execution timeout of an ASP.NET request through the config file. All you need to do is to set the executionTimeout attribute on the httpRuntime element in either the web.config (for one ASP.NET application) or even the machine.config (to affect all ASP.NET applications):
<httpRuntime executionTimeout="200"/>
According to the online documentation the executionTimeout is a TimeSpan attribute that “specifies the maximum number of seconds that a request is allowed to execute before being automatically shut down by ASP.NET”. (BTW, it doesn’t work in debug mode)
The default value for this attribute has been set to 90 seconds in ASP.NET 1.x and was increased to 110 seconds in ASP.NET 2.0.
Internally the timeout is managed by a timer (an instance of a System.Threading.Timer class) which is fired every 15 seconds.
Internally ASP.NET uses a Timer (an instance of System.Threading.Timer) to invoke the request cancelation process. This timer is fired once every 15 seconds, so if the executionTimeout is set to 3 seconds, in reality the request can timeout at any time between 3 seconds and 18 seconds.
When the timer is fired, a thread from the ThreadPool is used to check all the requests. The ones that have timed out are sent a ThreadAbortException by calling Abort on the thread executing the request.
So as per above, the executionTimeout only specifies the minimum duration that the request is guaranteed to be executed. The actual timeout can happen between executionTimeout and executionTimeout + 15 seconds.
Comments
Anonymous
October 01, 2007
PingBack from http://www.artofbam.com/wordpress/?p=4467Anonymous
October 02, 2007
As you are probably aware Thread.Abort() raises a ThreadAbortException in the thread on which it is invoked,Anonymous
January 31, 2008
The class responsible for this is System.Web.RequestTimeoutManager.Anonymous
June 18, 2008
This post was incredibly informative and helpful. Thanks for posting it!Anonymous
January 02, 2009
This info is tough to find. Thanks for posting!Anonymous
March 04, 2010
The comment has been removedAnonymous
April 04, 2011
Would nevery have found this anywhere else!Anonymous
July 05, 2011
NOTE: The following steps apply to ASP.NET 2.0 (32 bit). They have not been tested in other versionsAnonymous
November 06, 2011
Thanks! interesting article though!Anonymous
January 30, 2013
Very interesting article with some good (regarding timer and timeout detail) facts.Anonymous
February 20, 2013
NOTE: The following steps apply to ASP.NET 4.0 (64 bit). They have not been tested in other versions