Orange is my favorite color

My apps use a variety of frameworks which offer a lot of rapid development and agility but they also come at the cost of slower startup times. For a Coldspring-based app with a large service layer, you could easily run into timeouts when initially loading the application. Here’s a simple function to temporarily extend the processing timeout during initialization using CFTHREAD and the Admin API:

<cffunction name="extendRequestTimeoutDuringInit" output="false" access="public" returntype="any">

  <cfthread action="run" name="delayRequestTimeoutDuringInit">
    <cfset thread.adminapi = createObject("component", "cfide.adminapi.administrator") />
    <cfset thread.adminapi.login('mysecretpassword') />
    <cfset thread.runtime = createObject("component", "cfide.adminapi.runtime") />
    <cfset thread.timeout = thread.runtime.getRuntimeProperty("TimeoutRequestTimeLimit") />
    <cflog file="application" text="Extending RequestTimeout to #2*thread.timeout# seconds" />
    <cfset thread.runtime.setRuntimeProperty("TimeoutRequestTimeLimit", 2*thread.timeout) />
    <cfset sleep(2 * thread.timeout * 1000) />
    <cfset thread.runtime.setRuntimeProperty("TimeoutRequestTimeLimit", thread.timeout) />
    <cflog file="application" text="Restored RequestTimeout to #thread.timeout# seconds" />


I call this in Server.cfc when my instance starts up but you could also call it from any reinit routine in OnRequestStart or OnApplicationStart. Previously when we pushed code, the first user request would kick off the initialization process while other requests queued. Many of those first requests would exceed our page timeout setting of 60 seconds. Running the above function uses a background thread to double the timeout and later reset it once the application has initialized so users no longer see timeout/error screens.

Comments are closed.