次の方法で共有


Session Loss due to Application Domain recycle- Basics

This is one of the most common issues that I see a lot and thought will blog about one of the reasons responsible for session loss.

You might have observed sometimes that the application seems to be working fine and you observe one of the below 2 outcomes.

1) Intermittently one of the requests takes a lot of time and it recovers on its own for the next request and so

2) Session loss issues intermittently. The objects you store in the session are lost intermittently and sometimes you might receive null reference exception.

Ideally the first request for an asp.net application takes more time compared to the upcoming requests as I need to create an application domain within the process. Application domain is a processing environment within the process where your code is loaded and request is processed. This domain is the same place where your process specific objects are also stored. If you are using in-proc mode for session state, then those session objects also reside in this part of the process. So in case even your process is intact and just application domain within the process recycles or goes down, you might observe session loss as mentioned above

How to detect if the application domain/app domain is getting recycled?

You can follow one of the below steps

Step 1:

Enable health monitoring using the below steps.

Go to C:\WINDOWS\Microsoft.NET\Framework'x'\vy\CONFIG directory and add the following to the <healthMonitoring><rules> section

<add name="Application Lifetime Events Default" eventName="Application Lifetime Events"

provider="EventLogProvider" profile="Default" minInstances="1"

maxLimit="Infinite" minInterval="00:01:00" custom="" />

Note: x is ‘32’ if 32 bit app and '64' if 64 bit app and y is ‘4.0.30319’ if .net 4.0 app and ‘2.0.50727’ if it is .net 2.0 app

Reference:

https://blogs.msdn.com/b/tess/archive/2006/08/02/asp-net-case-study-lost-session-variables-and-appdomain-recycles.aspx

Step 2:

Also you can enable the event logging on app domain recycling in code as suggested the below blog

https://weblogs.asp.net/scottgu/433194

Step 3:

You can add a Perfmon counter and monitor your server as below
1) Click Windows Start button -> Run. Type Perfmon and click Ok.
2) Expand Performance Logs and Alerts.
3) Right click Counter Logs and select New Log settings.
4) Type a name and click Ok.
5) Click on Add Counters button.
6) From the Performance object select ASP.NET v.1.1.4322 or the ASP.NET version of your application.
7) Choose Select counters from list and select Application Restarts.
8) Click Add, Close, and Ok.
9) You will notice that the Perfmon will start logging data into this log file.

Once the issue happens you would observe the counter increasing.

Most common reasons for App domain recycling:

1) Antivirus Scans: You can get rid by excluding your framework, Application directories from scanning

More info on the directories to be excluded from antivirus scan can be found in the below blog

https://blogs.msdn.com/b/amol/archive/2015/12/10/asp-net-anti-virus-exclusion-list.aspx
2) Group policies changing or modifying framework folders or application folders either the permissions or the folder contents
3) Machine.Config, Web.Config or Global.asax are modified
4) The bin directory or its contents is modified
5) Exceeding the number of recompilation.

Usually by default the number is 15 and you can check this under numRecompilesBeforeAppRestart tag in machine.config or web.config: numRecompilesBeforeAppRestart property Gets or sets the number of dynamic recompiles of resources that can occur before the application restarts.

6) The physical path of the virtual directory is modified
7) The CAS policy is modified.
8) The web service is restarted.
9) Application Sub-Directories are deleted.

10) Writing files within web application or website directory.

These are some of the basic checks we can do to identify if the issue we are facing is because of Application Domain Recycling.

In the next series of blogs I am going discuss how to collect much more advanced data and how to look into these data to identify the root cause.

Hope this helps Smile

 

Technorati Tags: app domain recycling,session loss,slowness,IIS,w3wp

Comments

  • Anonymous
    November 29, 2016
    cartierbraceletlove Thanks Pat for this great list. Plugins are a necessity and knowing which one works is really helpful. I will keep your site bookmarked for your great information. Thanks, Stevenbracelet love cartier or jaune faux http://www.fashionlovebangle.cn/fr/
  • Anonymous
    December 15, 2016
    Hi Chiranth,thank you for this great article.Could you please explain how the number of recompilations can be exceeded if we have views provided via VirtualPathProvider in ASP.NET MVC web site?Our site looks to experience app domain restarts, however we do not see any evidences of changes of web site folder, .configs, etc (that you listed in Most common reasons for App domain recycling).Thank you.
    • Anonymous
      December 18, 2016
      As i have mentioned increasing number of recompilations is just a work around and the problem might increase and even cross the threshold you would set. you might want to figure out the actual reason. If you are using VistualPathProvider to store the views in a database, may there is a change notification coming in from the database itself which is one more thing you can get confirmed from your DB team. ALso you can try playing around with the cache dependency settings and try out