Skip to content

Unexpected cftimer Behavior

by Mike on July 18, 2006

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

Failed to add HTML header.


ColdFusion was unable to add the header you specified to the output stream. This is probably because you have already used a CFFLUSH tag in your template,or buffered output is turned off

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.


	



Now try changing type to “comment” and execute the code and you will see an exception. Here’s a sample…


	



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


	



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

From → ColdFusion

3 Comments
  1. klh permalink

    you have the coolest blog of all time!

  2. Chris permalink

    Great finding, Mike !
    I’d also been beating my head against the wall for many hours (it still hurts..). Too bad I had not found your article sooner.
    I discovered that bug too by a process of elimination (puting code blocks one by one in comment tags) to find out finally that it was the cftimer (type=comment in my case) that f*** the whole thing up. As you, I was puzzled why it was working fine on production server (with the showdebug OFF) and not on my dev server (with the showdebug ON).

  3. Thanks!! i even didn’t knew that cfflush was causing this error lolz.. thanks a lot!!

Comments are closed.