72

I have been searching for info on this to no avail. The context of why i need this is another question I asked here. More specifically, does creating/updating/deleting files in App_Data cause a pool recycle?

If someone could provide a detailed list of what causes a recycle, that would be great.

UPDATE: As two users already noticed I would also be happy to an answer specifying reasons for recycling the AppDomain only and not the whole pool.

Community
  • 1
  • 1
Slavo
  • 15,255
  • 11
  • 47
  • 60

6 Answers6

40

The article you liked in the other post actually did a really good job of this.

Immediate Recycle

  • Web.config changes
  • Machine.config changes
  • Global.asax changes
  • Bin directory changes
  • App_Code changes

Delayed Recycle

Can occur with multiple changes in other locations, typically, I've only noticed this with changes to .aspx or .cs/.vb files though. Adding temporary text, csv or other files has not resulted in issues for me.

NOTE: These are all app-domain recycles, and not actual recycles of the pool. Typically the application POOL will only recycle based on settings in IIS (Number of requests, memory limit, idle time, or scheduled restart).

Mitchel Sellers
  • 62,228
  • 14
  • 110
  • 173
  • 1
    Thanks, Mitchel. But it doesn't say anything about App_Data in particular. While here is says all App_ folders: http://weblogs.asp.net/owscott/archive/2006/02/21/ASP.NET-v2.0-_2D00_-AppDomain-recycles_2C00_-more-common-than-before.aspx#440333 – Slavo Nov 19 '08 at 16:09
  • Which one do I believe - these are exactly the inconsistencies, because of which I wasn't able to find one single answer. – Slavo Nov 19 '08 at 16:10
  • Slavo, this is true, however, I would be cautious as to the dates of the articles, as I know various service packs have modified this behavior at various points down the line. – Mitchel Sellers Nov 19 '08 at 21:34
  • I just changed a file in an App_Data folder and it caused a recycle, however, I should note that it was on my development server. I will find out shortly if it impacts production. – Dan Doyon Mar 15 '12 at 03:36
  • changing text files like aspx files, etc. will cause a recompile and will eventually trigger a restart of the application pool as well. There is a property of the compilation element under system.web that is called numRecompilesBeforeAppRestart. The default value is 20. This means that after 20 recompiles the application pool will recycle. – Rob Sedgwick Dec 17 '14 at 14:35
32

Two different effects:

  • The AppPool process is the host for potentially multiple AppDomains. Typically this can be recycled by a number of effects. These could be time (every n hours), lack of requests, memory use, etc.; all configured in IIS Config Manager.

  • The AppDomain, the hosted instance of your application root, can be cycled more frequently without affecting other AppDomains in the AppPool. Tess's post on AppDomain recycling is pretty insightful.

You are writing to a folder monitored for recompilation. This will trigger the AppDomain recreation at some point.

The event log will help you determine what cause initiated the recycle.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
stephbu
  • 5,072
  • 26
  • 42
  • 1
    Note that, in my testing, changes to configuration files referenced via sections with a configSource attribute in the Web.config will also cause an app domain restart. – Shaun Dec 03 '18 at 16:09
  • Yeah quite possible Shaun, this answer was written 10 years ago, when configSource was just an idea in a backlog :-) The schema has changed quite a lot since - would welcome editing of this answer to reflect the progress since then. I'm mildly entertained that this answer is still valid and actively trafficked. – stephbu Dec 05 '18 at 07:01
27

You might want to turn on full AppPool Recycle Event logs:

cscript adsutil.vbs Set w3svc/AppPools/DefaultAppPool/LogEventOnRecycle 255 

You also might want to take a look at this Scott Guthrie blog article: http://weblogs.asp.net/scottgu/archive/2005/12/14/433194.aspx that shows how to write code in Global.ASAX to log the actual cause of an Application.End event.

This has been extremely useful to us in diagnosing several screwy issues - one in partictual was an app that was writing log files to the wwwroot directory - too many file changes resulting in a recycle...

Christopher G. Lewis
  • 4,777
  • 1
  • 27
  • 46
  • 1
    FYI: adsutil.vbs should already exist on the machine. On my machine, it lives in both c:\Inetpub\AdminScripts\ and c:\WINDOWS\ServicePackFiles\i386. – Jim G. Aug 27 '09 at 12:45
  • @Christopher_G_Lewis can you elaborate on the issue that you stated, writing log files to the wwwroot directory - too many file changes resulting in a recycle. – Bhagirath N Sai Jan 09 '15 at 09:44
  • @Bhagirath-N-Sai - IIS will recycle the app pool if the FCN detects certain changes - see [Common reasons why your application pool may unexpectedly recycle](http://blogs.msdn.com/b/johan/archive/2007/05/16/common-reasons-why-your-application-pool-may-unexpectedly-recycle.aspx) – Christopher G. Lewis Jan 09 '15 at 21:39
  • @Christopher_G_Lewis could you help me out in http://stackoverflow.com/questions/27859599/erratic-behavior-of-preload – Bhagirath N Sai Jan 10 '15 at 02:48
2

This can happen on a daily basis based on preferences, or when the max virtual memory for the process has been exceeded.

Ben Scheirman
  • 40,531
  • 21
  • 102
  • 137
  • I understand these causes. I was rather asking about what application (not IIS related) changed would cause a recycle. – Slavo Nov 19 '08 at 14:58
  • Ahh, ok. Changing the app_data folder shouldn't recycle, but you might consider writing to a log when the applicaiton_start happens so that you can tell for certain. – Ben Scheirman Nov 19 '08 at 15:03
  • That's what I'll do after I get a few responses here :) – Slavo Nov 19 '08 at 16:11
1

This is a setting you can manipulate to recycle the app pool based on the number of minutes it has been running, or the number of requests it has processed.

It will also recycle on web.config changes and other things that have been posted here.

An IIS reset will also do the trick, as will stopping/starting services.

Milner
  • 638
  • 7
  • 19
0

w3wp.exe was erroring out. This was causing Application_Start to be called in Global.asax.

To find this out, I opened Event Viewer.

Under Windows Logs I went to Application.

I saw an Application Error:

Faulting application name: w3wp.exe, version: 10.0.16299.15, time stamp: 0x0aeb5595
Faulting module name: KERNELBASE.dll, version: 10.0.16299.334, time stamp: 0x6369e29f
Exception code: 0xe0434352
Fault offset: 0x0000000000014008
Faulting process id: 0x2900
Faulting application start time: 0x01d43b16f726cbb9
Faulting application path: c:\windows\system32\inetsrv\w3wp.exe
Faulting module path: C:\WINDOWS\System32\KERNELBASE.dll
Report Id: 998cf55d-2cd9-4b8d-9884-2110e3fd1411
Faulting package full name: 
Faulting package-relative application ID: 
Jesus is Lord
  • 14,971
  • 11
  • 66
  • 97