How is this timeout on CFLOOP possible?
I've been having troubles with a particular hosting provider for a client's site, and rather than going on a rampage about my troubles with the provider, let me get to the really odd error that I get on the hosted site intermittently, but cannot duplicate on my development box.
Here is the offending code:
<cfloop index="i" from="1" to="#Dir.RecordCount#"><cfset numArray[i]=i></cfloop>
<cfset QueryAddColumn(Dir,"Num",numArray)>
Sometimes this will process in a second and move on, other times the page will sit there for 30 seconds, time out, and then report, "The request has exceeded the allowable time limit Tag: CFLOOP".
Never mind even why I may be doing this or if there is a better way.. I'd like to know how this is even feasible. I know <cfloop> is obviously a candidate for infinite loops, but I'm looping over files in a directory that won't number more than a few hundred. Heck, even if for some crazy reason the record count provides a number in the millions, I'm executing such a simple command that it should take a couple seconds at most.
I don't understand how this error is feasibly possible without there being serious issues with the ColdFusion service on the server, which I actually wouldn't doubt.

September 26th, 2007 at 4:10 pm
The timeout messages in CF can be misleading. I suspect it’s actually timing out on the CFDIRECTORY line (which is probably because a file is in use and it’s causing issues with reading the files.)
The reason the message can sometimes be misleading is because CF won’t actually timeout after XX seconds on some operations (such as a CFQUERY operation.) It actually has to complete the full operation first.
So if you have a query that takes 60 seconds to run, but your template timeout is set to 30 seconds the query won’t just stop after 30 seconds. It’ll run the entire query first and then throw an error (so the error would occur after 60 seconds, not 30 seconds.)
Also, since that operation completes, the error that is reported as “timing out” is actually the next line that gets executed.
That’s why I suspect it’s actually the CFDIRECTORY tag that’s causing the timeout.
September 27th, 2007 at 4:21 pm
Wow. Seven years of developing in CF and I’ve never seen a situation where that was the apparent answer. Of course, I’ve spent most of that developing apps for a server that I control. Thanks for that insight.
It’s still weird that CFDIRECTORY would timeout. One time it will execute in less than a second, then next time it times out. And naturally, the hosting company refuses to lift a finger. I swear I must be the only CF customer on this server.
December 15th, 2007 at 8:28 am
What version of Coldfusion server are you running? I have the same problem with coldfusion 8, same code ran fine on coldfusion 5, now it is timing out on cfdirectory…
December 16th, 2007 at 12:27 am
Mike, this was on a CFMX 7 server. I wouldn’t be surprised if this behavior has been around since CFMX 6, though. I would seriously look into the possibility of a timeout from a related function, like Dan suggested. I highly suspect this was the issue for my situation.