Remember session scope does not exist in onApplicationStart()


Remember session scope does not exist in onApplicationStart()

Posted by Luis Majano
Aug 21, 2009 00:00:00 UTC
Are you getting this error:

Cannot lock session scope.

CFLock cannot be used to lock the application or session shared scopes without these scopes being established through the use of the CFApplication tag. If you want to use the session scope you need to enable session management. Application and/or Session variables must also be enabled in the ColdFusion Administrator.

Most likely you either do not have sessionmanagement enabled in your Application.cfm or Application.cfc or you are trying to use a session lock within your onApplicationStart() method of Application.cfc.

This is a reminder and a gotcha that session scope does not exist until onApplicationStart() finishes executing. The interesting thing also, is that in Railo 3.1 session does exist!

Anyways, beware the lock of session or acessing session from onApplicationStart().

 


Adam Cameron

Hi: I would say that if Railo handles this this differently than CF, then that's a bug in Railo.

It makes no sense to be doing things with the session scope in onAPPLICATIONstart() anyhow. Only the first "session" to ever hit the application would see the impact of the code. It makes sense to not have it available until onSESSIONstart().

-- Adam

Luis Majano

Hi Adam,

Just because CF handles something different, it doesn't mean that is right. Look at how CF handles arrays? That just doesn't make it right.

However, in my opinion, session object SHOULD be defined, because the pseudo-constructor runs FIRST! That is where you are defining session management and not in the onApplicationStart() method.

Just like the cf bug where even if you disable session, then isDefined() comes in as true, which should be fixed in 9.

So in conclusion, in my opinion this behavior should not be so as in the pseudo constructor you are expressing you want sessions.

Site Updates

Entry Comments

Archives

Entries Search