Twitter: raymondcamden


Address: Lafayette, LA, USA

Avoid Zero (or super short) Application Timeouts

08-08-2014 2,721 views ColdFusion 4 Comments

So here's a doozy for you. Over the past week or so I exchanged emails with a reader who was having an odd issue with ColdFusion mappings. Specifically the code he wrote to actually use the mappings would fail to work if he used application specific mappings. Switching to mappings defined on the server fixed it.

After I failed to notice it (and you can guess what's coming up based on the title of the entry), user BKBK on the Adobe forums pointed out that he had a 0-length application timeout: this.applicationTimeout = createTimeSpan(0,0,0,0);. Basically the application, and its settings, including the application mappings, timed out before his code could use it.

Why did he have it in the first place? He wanted a simple way to reload the Application on every request. For that I'd simply use a hook in your onRequestStart to run onApplicationStart():

function onRequestStart(string req) {
  onApplicationStart();
}

To be clear, this is not really reloading the application. It is just manually running your onApplicationStart method which is - 99% of the time - probably want you want. (During testing anyway, not in production.) You can also wrap that with a simple if(structKeyExists(url, "init")) block as well.

4 Comments

  • Commented on 08-08-2014 at 3:33 PM
    A lot of hay has been made with instantiating components in the application scope.

    This meant that you'd have to reload the application every time you made a change to a component.

    But ColdFusion and Railo have made tremendous speed gains in terms of components being instantiated.

    I no longer use the Application scope to store my components. I simply instantiate them when I need them.

    The only time I forsee putting a component in memory is if I'm calling it inside a loop.
    And with all the different layers of caching, it's probably in memory anyway.
  • Commented on 08-09-2014 at 1:25 AM
    So does this mean that settings a request acquires from the application, like mappings, ORM settings, what-have-you are removed - mid request - if the application times-out?

    And application idle time is based on when the most recent request STARTS, not when it ENDED?

    Both sound like our design to me..?

    --
    Adam
  • Commented on 08-09-2014 at 1:26 AM
    Oops! "poor design" not "our design".
  • Commented on 08-09-2014 at 7:50 AM
    Well, I tried to build a small test to demonstrate this. I used the cfapplication tag in a non-Application.cfm file, which you are allowed to do of course, and used sleep(). I wasn't able to replicate it there. But I still think it might be the start of a request as you say.

    I could see the reasoning behind that being that if you wait till the end, your app, or session, may time out at a value longer than you defined because the request took look.

    Not saying that's why, just that it may be a reason.

Post Reply

Please refrain from posting large blocks of code as a comment. Use Pastebin or Gists instead. Text wrapped in asterisks (*) will be bold and text wrapped in underscores (_) will be italicized.

Leave this field empty