PanJanek
PanJanek

Reputation: 6685

IIS pool recycle, pool restart, app restart, web.config update - global asax

I have MVC3 web application running under IIS 7. During initialization in global.asax application scans all the assemblies returned by BuildManager.GetReferencedAssemblies(), and all the types (Assembly.GetTypes()) in those assemblies in order to do initialization stuff.

From time to time the application stops working properly - it behaves as if the initialization never happened or some types were omited during startup. Once the application enters this failed state (I think it happens after the pool is recycled) it stays that way until restarted by:

  1. Manual updating Web.Config (adding some spaces)
  2. Manual restarting Application in IIS Manager
  3. Manual stopping and starting application pool in IIS Manager
  4. Automatic pool recycle

I noticed that 1. always helps, but 2,3,4 works indeterministically - at least as far as I can say because the nature of the problem is not deterministic - application crashes only after some scheduled recycles. What is the difference between 1 and 2,3,4 from the point of view of global.asax code and access to loaded assemblies?

Oh, the application runs as a sub-application (subfolder in IIS sites tree) if it changes anything.

Upvotes: 4

Views: 4804

Answers (1)

Matías Fidemraizer
Matías Fidemraizer

Reputation: 64943

I believe your problem could be solved by saving some state information so application can be aware about if its startup was successful.

Whenever application checks there's something incorrectly initialized, it should re-initialize it or throw an exception and restart application.

It's really hard to give you an solution, but summarizing you can do this:

  1. Track initialization.
  2. Don't let application run in an unexpected state.
  3. Double check if some unmanaged resource isn't being released somewhere in your code (maybe file streams, database connections...?).
  4. Logging, logging, logging...

Directly answering to your question:

  1. Recycles application pool.
    • HttpApplication (Global.asax) fires application initialization events (Start event).
  2. Recycles application pool.
    • HttpApplication (Global.asax) fires application initialization events (Start event).
  3. Basically, stops application for all incoming request until you start it again. Basically, a hard application pool recycling.
    • HttpApplication (Global.asax) fires application initialization events (Start event).
  4. Recycles application pool.
    • HttpApplication (Global.asax) fires application initialization events (Start event).

Basically, any of these actions produces the same result.

Have you tried to do an IIS reset - iisreset /restart command -? This should release any locked resource and stop any unwanted loop, thread or whatever thing crashing your application.

Upvotes: 1

Related Questions