OnSessionEnd triggered but session does not end


I recently moved a site from CF10 to Lucee running on Tomcat 8.0.32, and I am running into a problem where around 5-6 sessions a day (out of a couple thousands) don’t end their sessions eventhough onSessionEnd() was triggered for them.

Here’s the relevant part of my Application.cfc

this.sessionTimeout = createTimeSpan(0,0,20,0);

function onSessionStart(){

   session.mySessionId = getTickCount() & session.cfid;


function onSessionEnd(sessionScope){

   // write to database
   queryExecute("insert into mylog( sessionId) values('#sessionScope.mySessionId#')");


The way I know that onSessionEnd() is triggered is because I get errors of Primary Key Violation (ie. sessionId) of sessions trying to insert the same mysessionId into mylog.

Typically (but not always), the errors would come 20 minutes apart. So it looks like the session was ending, but a new session gets triggered without hitting onSessionStart() (because that would have created a new session.mySessionId).

Any suggestion as to what could be causing it? Thanks.