Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS6: When an app pool is recycled, is Session_End called?

Tags:

iis

iis-6

I need to know because I have to explicitly close some remote resources that are tied to the user's session.

like image 368
Jonathan Allen Avatar asked Mar 29 '10 18:03

Jonathan Allen


People also ask

What happens when an IIS app pool recycles?

What is application pool recycling in IIS? Recycling means that the worker process that handles requests for that application pool is terminated and a new one is started. This is generally done to avoid unstable states that can lead to application crashes, hangs, or memory leaks.

Why is the IIS default app pool recycle set to 1740 minutes?

The 1740 story Wade suggested 29 hours for the simple reason that it's the smallest prime number over 24. He wanted a staggered and non-repeating pattern that doesn't occur more frequently than once per day. In Wade's words: “you don't get a resonate pattern”. The default has been 1740 minutes (29 hours) ever since!

How often does IIS recycle app pool?

By default, an IIS application pool (or “AppPool”) recycles on a regular time interval of 1740 minutes, or 29 hours. One reason for this time interval is that application pools don't recycle at the same moment every day (every day at 07.00 for example).


2 Answers

I must disagree with Darin. I call a function in Session_End to record the end of the session. I have not tested this explicitly, but I looked in my logs for the last few times that the app pool recycled. The function got called and the end of the active sessions got logged.

This occurred both when the app pool recycled on a schedule, and when it recycled because I deployed some new dlls.

like image 81
Ray Avatar answered Sep 28 '22 00:09

Ray


If I recall correctly (been a while since I read the docs) having active sessions will delay the normal App pool recycling timer (which fires when the resources should be freed) because the server banks on active sessions meaning that there is continued need. Once the sessions expire (and fire the session_end event) the app recycle timer starts over and counts down, eventually firing before the thread pool releases its own resources and terminates the app.

That is under normal circumstances, it should be noted that the session_end event is not guaranteed to fire (there use to be very specific scenarios where it would not), I think now this is mostly related to crashed instances of IIS or App Pool recycles for OOM or errors. It use to be unless you were using just one of the session types (state server I believe) it would not reliably fire. This may be different now.

If you need to guarantee that resources are freed, I am not sure session_end is the appropriate place to do it. Can you elevate it to the App Cache or HTTP Cache and use session unique keys with periodic cleanup events? That might be more reliable (more code) but more reliable.

It has been my general experience that session_end fires fairly reliably, but I have seen it fail under substantial load (100s of hits a second) and I know when you start talking about server farms it gets vastly more complicated as well.

like image 36
GrayWizardx Avatar answered Sep 28 '22 00:09

GrayWizardx