tracker issue : CF-4087458

select a category, or use search below
(searches all categories and all time range)
Title:

[ANeff] Bug for: OnSessionEnd() never runs after ApplicationStop()

| View in Tracker

Status/Resolution/Reason: To Fix//EnhancementRequired

Reporter/Name(from Bugbase): Aaron Neff / Aaron Neff (Aaron Neff)

Created: 11/15/2015

Components: Language, CF Component

Versions: 11.0

Failure Type:

Found In Build/Fixed In Build: CF11_Final /

Priority/Frequency: Major / Some users will encounter

Locale/System: English / Windows 10 64 bit

Vote Count: 0

If ApplicationStop() is called, then OnSessionEnd() never runs. Same issue regardless if J2EE sessions are enabled or not.

Repro:

1) Run the code below (without ?reinit URL parameter)
2) Open ticket_OnSessionEndNotCalledAfterApplicationStop.log
3) See "onSessionEnd" was logged (good)
4) Run the code below w/ the ?reinit URL parameter
5) Open ticket_OnSessionEndNotCalledAfterApplicationStop.log
6) See "onSessionEnd" was never logged (bug)

Application.cfc
----------------------
component {
    THIS.name = "ticket_OnSessionEndNotCalledAfterApplicationStop";
    THIS.applicationTimeout = createTimeSpan(0,0,0,20);
    THIS.sessionManagement = true;
    THIS.sessionTimeout = createTimeSpan(0,0,0,10);

    boolean function onApplicationStart() {f("onApplicationStart"); return true;}

    void function onSessionStart() {f("onSessionStart");}

    boolean function onRequestStart() {
        f("onRequestStart");
        if(URL.keyExists("reinit")) {
            applicationStop();
        }
        return true;
    }

    void function onRequestEnd() {f("onRequestEnd");}

    void function onSessionEnd() {f("onSessionEnd");}

    void function onApplicationEnd() {f("onApplicationEnd");}

    function f(required string methodName) {
        writeLog(ARGUMENTS.methodName, "information", true, THIS.name);
    }
}
----------------------

index.cfm
----------------------
[empty file]

----------------------------- Additional Watson Details -----------------------------

Watson Bug ID:	4087458

External Customer Info:
External Company:  
External Customer Name: Aaron Neff
External Customer Email:  
External Test Config: Verified in CF11 Update 5 (build 11,0,05,293506) and build (11,0,0,296013)

Attachments:

Comments:

Why is this a bug? If you have stopped the application, how can the events be called on it?
Comment by Rupesh K.
5346 | November 15, 2015 11:58:46 PM GMT
Hi Rupesh, I'd imagine the same way onApplicationEnd() and onRequestEnd() events are called on it after applicationStop(). Thanks!, -Aaron
Comment by External U.
5347 | November 16, 2015 12:08:40 AM GMT
Hi Rupesh, ApplicationStop() does not end the session. OnSessionEnd() should always be called at the end of each session. If OnSessionEnd() cannot be called in the same manner as OnApplicationEnd() and OnRequestEnd() can be called, then perhaps ApplicationStop() should do the following: 1) pause the current thread and wait until all other currently-running requests have ended 2) end all the other sessions 3) end the current thread's request/session 4) end the application I don't think ApplicationStop() would need to queue new requests, b/c currently new requests just get assigned to a new application instance - and that is fine I think. Thanks!, -Aaron
Comment by External U.
5348 | November 16, 2015 12:40:05 AM GMT
I don't think that all the active sessions should be closed when the applicationstop is called. While one's session is active, even if the application was stopped, the next request would automatically re-initialize the application and the session would continue to work. Moreover, ApplicationStop is not usually used in production.
Comment by Rupesh K.
5349 | November 16, 2015 01:16:46 AM GMT
ApplicationStop() is required for reloading JavaSettings and shouldn't prevent OnSessionEnd() from being called when currently-active sessions end. Thanks!, -Aaron
Comment by External U.
5350 | November 16, 2015 02:04:36 AM GMT
Hi Rupesh, I agree that ApplicationStop() shouldn't close sessions. But when a session ends, OnSessionEnd() should be called. Always. Thanks!, -Aaron
Comment by External U.
5351 | November 16, 2015 02:12:46 AM GMT
That's the question - how would that happen? session usually live for quite a long time. Usually the session timeout is 20 minute and can be higher as well. If the application is not there when the session times out or ends, how would it call onSessionEnd? A similar situation is there for Server restart. All the sessions would end when the server stops and at that time also, onSessionEnd cant be called.
Comment by Rupesh K.
5352 | November 16, 2015 02:38:20 AM GMT
Hi Rupesh, Server restart is different b/c we aren't explicitly invoking a ServerStop() or ServerRestart() function. So, it is understandable that onSessionEnd() isn't called in that case. For ApplicationStop(), we are explicitly/knowingly wanting to restart/reset the application. More specifically, we are wanting to reset things such as THIS.javaSettings (and, previously, THIS.datasources) (and any settings CF adds later that would require an application reset to re-evaluate) and have OnApplicationEnd() and OnApplicationStart() run again. That's all. We don't want the current request, and all other currently-running requests, to continue running in a defunct state w/o their per-app mappings and stuff. And we don't want OnSessionEnd() to not be called. ApplicationStop() doesn't even clear the application scope (that right there is an inconsistency). Looks like what we really want is for ApplicationStop() to set a flag that the next request should call OnApplicationEnd() and OnApplicationStart(). Or an ApplicationRestart() function that does this. Thanks!, -Aaron
Comment by External U.
5353 | November 16, 2015 03:55:39 AM GMT
And, regarding ApplicationRestart(), it should associate existing sessions to the new application.
Comment by External U.
5354 | November 16, 2015 03:58:24 AM GMT
" If the application is not there when the session times out or ends, how would it call onSessionEnd? " The session tracking and *management* should not be intrinsically interlinked to the application management. The only interlink should be a reference to the application for the session. Just because that reference might no longer be valid should not impact the session manager tidying up sessions.
Comment by External U.
5355 | November 16, 2015 04:13:29 AM GMT
We will investigate this and see if something can be done.
Comment by Vamseekrishna N.
5356 | October 03, 2016 12:04:55 AM GMT