title: Increase request timeout for a thread in CFML
body: <p>I have a web application that is generating hundreds of PDFs in batch, using ColdFusion 8 on a Windows/IIS server.</p>
  
  <p>The process runs fine on my development and staging servers, but of course the client is cheap and is only paying for shared hosting, which isn't as fast as my dev/staging boxes. As a result, PDF generation threads are timing out.</p>
  
  <p>The flow is something like this:</p>
  
  <ol>
  <li>Page is run to generate PDFs.</li>
  <li>A query is run to determine which PDFs need to be generated, and a loop fires off an application-scoped UDF call for each PDF that will need to be generated.</li>
  <li>That UDF looks up information for the given item, and then creates a thread for the PDF generation to work in, preventing generation from slowing down the page.</li>
  <li>The thread simply uses CFDocument to create a PDF and save it to disk, then terminates.</li>
  </ol>
  
  <p>Threads do not re-join, and nothing is waiting for any of them to finish. The page that makes the UDF calls finishes in a few milliseconds; it's the threads themselves that are timing out.</p>
  
  <p>Here is the code for the UDF (and thread creation):</p>
  
  <pre><code>&lt;cffunction name="genTearSheet" output="false" returntype="void"&gt;
      &lt;cfargument name="partId" type="numeric" required="true"/&gt;
      &lt;!--- saveLocation can be a relative or absolute path ---&gt;
      &lt;cfargument name="saveLocation" type="string" required="true"/&gt;
      &lt;cfargument name="overwrite" type="boolean" required="false" default="true" /&gt;
      &lt;cfset var local = structNew() /&gt;
  
      &lt;!--- fix save location if we need to ---&gt;
      &lt;cfif left(arguments.saveLocation, 1) eq "/"&gt;
          &lt;cfset arguments.saveLocation = expandPath(arguments.saveLocation) /&gt;
      &lt;/cfif&gt;
  
      &lt;!--- get part info ---&gt;
      &lt;cfif structKeyExists(application, "partGateway")&gt;
          &lt;cfset local.part = application.partGateway
          .getByAttributesQuery(partId: arguments.partId)/&gt;
      &lt;cfelse&gt;
          &lt;cfset local.part = createObject("component","com.admin.partGateway")
          .init(application.dsn).getByAttributesQuery(partId: arguments.partId)/&gt;
      &lt;/cfif&gt;
  
      &lt;!--- define file name to be saved ---&gt;
      &lt;cfif right(arguments.saveLocation, 4) neq ".pdf"&gt;
          &lt;cfif right(arguments.saveLocation, 1) neq "/"&gt;
              &lt;cfset arguments.saveLocation = arguments.saveLocation &amp; "/" /&gt;
          &lt;/cfif&gt;
          &lt;cfset arguments.saveLocation = arguments.saveLocation &amp; 
          "ts_#application.udf.sanitizePartNum(local.part.PartNum)#.pdf"/&gt;
      &lt;/cfif&gt;
  
      &lt;!--- generate the new PDF in a thread so that page processing can continue ---&gt;
      &lt;cfthread name="thread-genTearSheet-partid-#arguments.partId#" action="run" 
      filename="#arguments.saveLocation#" part="#local.part#" 
      overwrite="#arguments.overwrite#"&gt;
          &lt;cfsetting requestTimeOut=240 /&gt;
          &lt;cftry&gt;
          &lt;cfoutput&gt;
          &lt;cfdocument format="PDF" marginbottom="0.75" 
          filename="#attributes.fileName#" overwrite="#attributes.overwrite#"&gt;
              &lt;cfdocumentitem type="footer"&gt;
                  &lt;center&gt;
                  &lt;font face="Tahoma" color="black" size="7pt"&gt;
                  pdf footer text here
                  &lt;/font&gt;
                  &lt;/center&gt;
              &lt;/cfdocumentitem&gt;
              pdf body here
          &lt;/cfdocument&gt;
          &lt;/cfoutput&gt;
          &lt;cfcatch&gt;
          &lt;cfset application.udf.errorEmail(application.errorEmail,
          "Error in threaded PDF save", cfcatch)/&gt;
          &lt;/cfcatch&gt;
          &lt;/cftry&gt;
      &lt;/cfthread&gt;
  &lt;/cffunction&gt;
  </code></pre>
  
  <p>As you can see, I've tried adding a <code>&lt;cfsetting requestTimeout=240 /&gt;</code> to the top of the thread to try and make it live longer... no dice. I also got a little excited when I saw that <a href="http://cfquickdocs.com/cf8/?getDoc=cfthread#cfthread" rel="nofollow noreferrer">the CFThread tag has a timeout parameter</a>, but then realized it only applies when joining threads (action=join).</p>
  
  <p>Changing the default timeout in ColdFusion Administrator is not an option, as this is a shared host.</p>
  
  <p>If anyone has any ideas on how to make these threads live longer, I would really appreciate them.</p>