Unexpected cftimer Behavior
This is a fun one, After beating my head against the wall for a bit, I discovered an interesting behavior when using cftimer and cfheader (or cflocation) together. Follow along….
First I saw this error….
Error Occurred While Processing Request
At this point, I thought to myself, “Thank you coldfusion, I must have a CFFLUSH tag somewhere in my code, this should be easy to find”. But, unfortunately this wasn’t the case… No CFFLUSH tags anywhere in the code… hmmm.
Finally, I figured it out. As far as I can tell, CFTIMER actually sends the buffer to the client when type is set to “inline” or “comment”. Take a look for yourself. With debugging/timer info enabled the following code executes without any problems.
1 2 3 4 5
<cftimer label="foo" type="debug"> <!--- Some Code Here ---> </cftimer> <cfheader name="Expires" value="#Now()#">
Now try changing type to “comment” and execute the code and you will see an exception. Here’s a sample…
1 2 3 4 5
<cftimer label="foo" type="comment"> <!--- Some Code Here ---> </cftimer> <cfheader name="Expires" value="#Now()#">
In my case, the error occurred only in a dev environment, when I was adding a cfheader tag. The timer tags had been in there for a while, so it was extremely hard to figure out why I was getting this error. An even more confusing situation would be the following code
1 2 3 4 5
<cftimer label="foo" type="comment"> <!--- Some Code Here ---> </cftimer> <cflocation url="index.cfm" addtoken="false">
In this case, the code would appear to execute without any problems, but would simply fail to do the redirect, think about how much time you could waste on that one if a cftimer tag is buried in your code.
Lesson of the day
Take note just in case you come across this. Additionally this should probably be added to liveDocs for cfheader and cflocation
Mike Schierberl is a software engineer located in San Francisco, CA. He specializes in Cloud Computing, E-Commerce, and Continuous Integration.