Why is <cfsetting requesttimeout="120" /> in the image formtool GenerateImage() function?

Why does GenerateImage() (in FarCry 6.2.x, at least) have <cfsetting requesttimeout="120" /> in it? It is causing problems with a script I’m writing that generates several images. No matter what I set my requesttimeout to in my script, the GenerateImage() function overrides it and sets it to 120 seconds. This causes my script to timeout after two minutes.

So, my question I guess, is why is this here? In other places in the framework you use the request monitor to find the current timeout and extend it:

From Application.cfc:

<cfif structkeyexists(server,"railo")>
  <cfsetting requesttimeout="#getPageContext().getRequestTimeout() + 5000#" />
<cfelseif structkeyexists(server,"coldfusion")>
  <cfsetting requesttimeout="#CreateObject("java", "coldfusion.runtime.RequestMonitor").GetRequestTimeout() + 5#" />
</cfif>

This extends the timeout instead of overriding it.

Can we modify the image formtool to use this technique (any also any other places that set an explicit request timeout)?

1 Like

I guess it’s there to avoid long running image crops taking up threads and killing the server (looks like it was added to p600 in March 2011), but as you say the placement of that tag blocks other long running threads from doing image crops themselves. For now if you are happy to remove the timeouts you can copy the image.cfc in to your project’s /packages/formtools folder and delete that 1 line of code.

Increasing the request timeout for each crop might not be desired in the context of a long running thread (e.g. you want it to time out after 5 minutes but depending on how many times the function is called it could end up running for much longer).

Perhaps the timeout needs to be moved into ftajax.cfm since most image crops happen via ajax calls which go through that controller, and for image crops that happen when an object is saved it could go into the image formtool’s ImageAutoGenerateBeforeSave() method (this one might have no timeout currently, other than the default request timeout). There might also be alternative methods of restricting the amount of time that an image crop runs for (based on current request execution time using getPageContext().getFusionContext().getStartTime(), or using a thread with a timeout).

Yeah, thats what I did (override in the project) but I’d rather not do that because the function could come out of date. Rather than remove the line, I replaced it with:

<cfif structkeyexists(server,"railo")>
  <cfsetting requesttimeout="#getPageContext().getRequestTimeout() + 120000#" />
<cfelseif structkeyexists(server,"coldfusion")>
 <cfsetting requesttimeout="#CreateObject("java", "coldfusion.runtime.RequestMonitor").GetRequestTimeout() + 120#" />
</cfif>

But, yes, I think you’re right, it should go in ftajax.cfm and wherever else this function might be called rather than in the function itself.

Had the same problem with GenerateImage() last week, I ended up with removing the timeout and handled the timeouts from the caller function.

Agree :slight_smile: