tags:

views:

38

answers:

2

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

+2  A: 

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.

Ray
Agreed, just tested and it fired :-)
Darin Dimitrov
A: 

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.

GrayWizardx
I'm only talking about 20-30 users max, but the cost of leaving the connection open is very high and I don't trust the remote server to close it.
Jonathan Allen