18

I've got an ASP.NET application running on IIS 7 with multiple application domains, and I can't fathom why there are multiple app domains in a single process. I've grepped my code base, and I'm not explicitly creating a second application domain. Is it possible that a recycle has failed to time out?

  • These double domains will persist for sometime.
  • If a recycle occurs because of a web config or binary change, both app domains will go down, and two new ones will start up.
  • These servers are subject to several binary patches and IISResets per day - sometimes there are 2 domains, sometimes only 1.
  • Web gardening is disabled.
  • I discovered this because there is a timer in the application heart-beating to the database, and noticed one day the server had two heartbeats.

In windbg, !dumpdomain shows me the following result: (filtered to only show names of app domains):

Line 59: Name:               None
Line 66: Name:               None
Line 372: Name:               DefaultDomain
Line 460: Name:               /LM/W3SVC/1/ROOT/MyAppDomain-1-129882892717131250
Line 4437: Name:               /LM/W3SVC/1/ROOT/MyAppDomain-4-129285605131450579
Dlongnecker
  • 3,008
  • 3
  • 25
  • 40
  • Fascinating :) When you open up Application Pools in IIS manager, select the pool this app runs in then select View Applications in the Actions pane on the RHS, how many apps are listed? – Kev Jun 07 '12 at 01:49
  • 1
    Good call - only one application. – Dlongnecker Jun 07 '12 at 02:49
  • Could it be some pressure management in IIS ? Under heady load - to create additional appDomain, otherwise to kill the unneeded one? Or something related to Rapid Fail Safe protection? A similar discussion : http://stackoverflow.com/questions/8979032/why-is-a-new-appdomain-being-created-every-few-seconds-wcf-iis-7 – Tisho Jun 12 '12 at 15:38
  • it might be a result of recycling, for how long do they persist? (if you can even check). Mayhaps you can check this somehow by using the Applicatin_End event? – YavgenyP Jun 12 '12 at 18:59
  • Hours - it's like the 90 second timer to forcefully unload the app domain never completes, or the app domain is stuck attempting to unload. – Dlongnecker Jun 12 '12 at 19:56
  • Is the heart-beat timer keeping the AppDomain alive itself? – Mark Hurd Jun 13 '12 at 02:12
  • Are you referencing another assembly that might be creating the AppDomain's? – Robert Jun 13 '12 at 07:33
  • @MarkHurd, I don't think so. The heartbeat's been running for a while without issues. The double domains is new. – Dlongnecker Jun 13 '12 at 17:15
  • @Robert - good point, I'll look into it. – Dlongnecker Jun 13 '12 at 17:15
  • Did you ever figure this one out? – smartcaveman Jul 07 '12 at 19:01

4 Answers4

7
  1. Even though you aren't creating an AppDomain, a library that you are using might be. What third-party components are you using? Do you have any Inversion of Control or Dynamic Proxy libraries that might be responsible? Here's an explanation of this happening with Castle.

  2. Are you sure the application is only running in one place in IIS? It's possible to have multiple IIS sites/applications running off of the same files. This would be consistent with (1) getting your debug info from the db, rather than the app, and (2) the recycle due to editing web.config consistently resulting in duplicate domains. If one location is more commonly accessed than the other this could explain why there is sometimes only one AppDomain.

  3. If you are leveraging ASP.NET's dynamic compilation and shadow copying feature, ASP.NET will at times have multiple AppDomains. Jim Schubert wrote an article called ASP.NET, AppDomains, and shadow-copying which explains this in more detail as well as makes several suggestions as to how to modify web.config to customize this. He also has a helpful answer over at Does my ASP.NET application stop executing if I overwrite the DLLs? Shadow copying can be disabled by setting <hostingEnvironment shadowCopyBinAssemblies="false" />.

Update

I got sucked into Jim Schubert's blog and ended up reading this unrelated post on Allowing Only A Single Instance of a .NET application. If all else fails, you could use this approach to ensure only one instance of the application is running.

Community
  • 1
  • 1
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
2

May have a look at your ApplicationHost.config.

have a look at: maxProcesses it should be 1.

It seems your IIS starts multiple worker-processes.

mo.
  • 3,474
  • 1
  • 23
  • 20
0

As suggested by the following answer https://stackoverflow.com/a/3318367/2001769 in another thread, it seems the ASP.NET runtime keeps a pool of HttpApplication instances (irrespective of maxProcesses / Web Garden).

I don't know if is possible, or even desirable, to control this pool. The best practice could be to instantiate all application singletons in the Application_Start event that is supposed to run only once per application and not once per pooled HttpApplication instance.

Community
  • 1
  • 1
Michael
  • 83
  • 4
0

If there are multiple IIS Applications targeting the same path. An AppDomain will be created per such IIS Application if the app is invoked.

For example:

If both target the same path they still count as two different applications and two AppDomains will be created.

ewolfman
  • 361
  • 3
  • 4
  • 18