Handling Sessions that Start before onApplicationStart is completed

20 views
Skip to first unread message

Randy Merrill

unread,
Jan 17, 2011, 11:10:35 AM1/17/11
to ra...@googlegroups.com
I have some code in my onApplicationStart that loads in some configurations, creates objects, etc. In order to minimize the amount of time that is spent with the application scope locked I am putting the new configs/objects into temporary variables and then just locking the application at the end of the function to put the data in place.

...
<cflock scope="application" type="exclusive" timeout="20">
<cfloop list="#structKeyList(tempApplication)#" index="i">
<cfset application[i] = tempApplication[i] />
</cfloop>
</cflock>
...

The problem that I am having is that the onSessionStart is firing before the onApplicationStart finishes. This causes the onSessionStart to fail because the application hasn't finished and it references the application.

How have others solved this issue? I would like to avoid having to lock the application for the entire onApplicationStart but I'm not sure how else to get the onSessionStart to wait until it is complete.

--
Randy Merrill

Todd Rafferty

unread,
Jan 17, 2011, 11:26:23 AM1/17/11
to ra...@googlegroups.com
How much stuff are you actually putting in the Application scope? Where is it coming from? What's actually causing the slowdown? Database?
--
~Todd Rafferty
Volunteer
Community Manager
Railo Server - Open Source
----

Randy Merrill

unread,
Jan 17, 2011, 11:33:31 AM1/17/11
to ra...@googlegroups.com
Mostly the application start is reading in configuration files, creating objects and otherwise instantiating singletons, etc. Usually it takes around 500-1000 ms to complete the first page load. There is also the chance that it can run some SQL, but when I am testing there is no SQL to run so it's all just file system and object work.

Is there a reason that the session can actually start before the application has completely startup? I can see trying to make it as fast as possible, but it seems it should at least wait for the application to start before running.
--
Randy Merrill

Todd Rafferty

unread,
Jan 17, 2011, 12:02:17 PM1/17/11
to ra...@googlegroups.com
So, the onApplicationStart() is actually hitting a file from the filesystem? XML File perhaps?

Randy Merrill

unread,
Jan 17, 2011, 12:15:29 PM1/17/11
to ra...@googlegroups.com
json, but close enough. :)
--
Randy Merrill

Todd Rafferty

unread,
Jan 17, 2011, 12:19:09 PM1/17/11
to ra...@googlegroups.com
Hopefully Micha can comment on this.

Are you actually doing a fileRead() to grab the file? or are you cfincluding it and have everything wrapped in cfsavecontent? I assume you're deserializing the json? What's the loop actually for?

Randy Merrill

unread,
Jan 17, 2011, 12:44:03 PM1/17/11
to ra...@googlegroups.com
It's doing a fileRead() then deserializes and uses the structure.

Most of the work in the application start is reading in plugin settings, checking to make sure that it isn't a new version of the plugin, creating any singletons needed, etc. Nothing too special.

I'm trying to create a test case that will reproduce it in a simpler form... I'll let you know when have something.
--
Randy Merrill

Sean Corfield

unread,
Jan 17, 2011, 12:46:37 PM1/17/11
to ra...@googlegroups.com
That sounds like a bug. onApplicationStart() should block all requests
until it is complete. You should not need any locks - that's the whole
point of onApplicationStart(): it should be single-threaded.

Please open a ticket in JIRA and I'll talk to Micha about it.

Sean

--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Randy Merrill

unread,
Jan 17, 2011, 4:40:29 PM1/17/11
to ra...@googlegroups.com
I actually was looking in slightly the wrong place, it is the onRequestStart that is firing before the onApplicationStart finishes.


I'm still working on an example that would trigger it, but I've included the stack trace that I get in case that helps.
--
Randy Merrill
Reply all
Reply to author
Forward
0 new messages