Skip to main content
December 31, 2010
Question

Application Scope within onSessionEnd

  • December 31, 2010
  • 3 replies
  • 2442 views

Hi,

Can someone enlighten me as to why application scope variables cannot be directly referenced from onSessionEnd?  I can understand session variables being unavailable in onSessionEnd, but shouldn't application scope vars still be available?  Why do we need to pass them as arguments into onSessionEnd?

    This topic has been closed for replies.

    3 replies

    Community Expert
    January 1, 2011

    I like Dan's answer, and Adam's is also plausible. Or maybe it's because - theoretically, at least - a session could expire at the same time as an application. But in any case, these are all guesses, and the real answer is "because Adobe says so".

    Dave Watts, CTO, Fig Leaf Software

    http://www.figleaf.com/

    http://training.figleaf.com/

    Dave Watts, Eidolon LLC
    BKBK
    Community Expert
    Community Expert
    January 1, 2011

    First of all, I wish you all a happy, healthy and prosperous New Year 2011 !

    Dave Watts wrote:

    I like Dan's answer, and Adam's is also plausible. Or maybe it's because - theoretically, at least - a session could expire at the same time as an application. But in any case, these are all guesses, and the real answer is "because Adobe says so".

    It's not all guesses, Dave. It's not only because Adobe says so either.

    OnSessionEnd is just an event-handler. As such, it is outside the normal program flow.

    However, ColdFusion needs to give us at least a way of identifying which session has ended.  In general, Coldfusion identifies a session by means of the application-name and the session tokens CFID and CFToken. Hence the need for Coldfusion to pass both the application scope and the session scope. There is one good reason why the application-scope argument that Coldfusion passes to the handler must pertain to the state of the application at the moment when the session ended: consistency.

    For, suppose, on the contrary, that Coldfusion made application.myVar available to the handler, rather than arguments.applicationScope.myVar.  Suppose also that my session has ended and it takes onSessionEnd 2 minutes to complete. A few seconds after my session ends, another user whose session is still alive modifies the value of application.myVar. This would result in inconsistency.

    Inspiring
    January 1, 2011

    For, suppose, on the contrary, that Coldfusion made application.myVar available to the handler, rather than arguments.applicationScope.myVar.  Suppose also that my session has ended and it takes onSessionEnd 2 minutes to complete. A few seconds after my session ends, another user whose session is still alive modifies the value of application.myVar. This would result in inconsistency.

    How does that differ from any other situation in which application-scoped variables are accessed?  You're just describing a potential race condition: there's nothing intrinsic to that which suggests onSessionEnd should handle the application scope differetly than any other code.

    --

    Adam

    BKBK
    Community Expert
    Community Expert
    December 31, 2010

    I think it's because ColdFusion holds sessions in memory within the context of an application. When the session ends, the user loses context. There must therefore be a way to give context back to the user. I believe that the sessionscope and applicationscope that ColdFusion automatically passes to the onSessionEnd actually define that context.

    The function getPageContext gives you an illustration of how the application and session scopes are inextricably linked. To see this, run

    <cfdump var="#getPageContext()#">. Look at Fields. You will see that the page context object links getPageContext().Application and getPageContext().Session among others.

    Inspiring
    December 31, 2010

    I imagine it's because the onSessionEnd handles is fired outwith the auspices of a given app? It's probably run by some clean-up agent or something, and it didn't occur to the Adobe engineers to run the request which does the clean-up in the same context as the app that it's for. If that makes sense. And it's also just a guess.

    --

    Adam