Thursday 16 January 2014

Weirdness with <cfflush>

I've found a weird thing... <cfflush> doesn't always seem to work. I don't mean the old "yeah, it doesn't work in custom tags" trope (or variations on that theme), I mean... with the same code, it will work on some CF installs, and will not on others.

Consider this test code:

<!--- testFlush.cfm --->
<cfinclude template="./udfs.cfm">

Beginning of request<br>
<cfset outputRandomLetters()>

After first flush<br>
<cfset outputRandomLetters()>

After second flush<br>
<cfset outputRandomLetters()>

End of request<br>

// udfs.cfm
function outputRandomLetters(){
    for (var i=1; i <= (128*1014); i++){

function makeHttpRequest(){
    return new Http(method="get", url="").send().getprefix().statusCode;

This is fairly straight fwd. I output lots of stuff, then flush it, then force there to be a pause in processing (random URL: it's my voting list on IMDB, which I happen to have in the other window @ the time). Rinse and repeat a coupla times.

I can't really represent the intended output of this without doing a Jing or something, and even then the correct output doesn't occur on this computer anyhow, so yer just going to have to take my word for it. What ought to happen is that at each <cfflush>, whatever is in the output buffer should be flushed down to the client browser. So one gets a partial response on the browser screen as server processing continues.

However when I run this code on my local machine (CF9.0.1 Enterprise 64-bit, IIS 7.5, Windows 7 Enterprise 64-bit), no flushing takes place. Initially I thought this was IIS - which I am not an admin of on this machine so cannot monkey with - as other people I got to run similar code had the same experience. This is documented as being an IIS config setting / issue.

But... it also doesn't work on this machine running ColdFusion 10 using the inbuilt web server either. Nor does it work on Railo Express (running on Jetty). So it's not just an IIS thing.

And, to make matters more interesting, the same code runs fine on my home machine on ColdFusion 10 (inbuilt Tomcat web server), Railo Express (Jetty), OpenBD (Jetty), and ColdFusion 9 (running JWS). And - as far as I know - the CF10 and Railo installs are pretty much exactly the same as the ones on this machine: bog standard default. In fact I only say "pretty much" because clearly they're not the same, but as far as I know they are the same.

I uploaded some test code to CFMLDeveloper and it doesn't flush there, but I knew that because this is where this investigation started.

If you've got some spare time could you possibly run that code on your rig, and lemme know whether flushing works for you? And lemme know what you're running.

There are some platform-neutral versions of this code in this Gist:

Cheers for any help or insight here. I'm trying to determine whether this is a bug of some description, or just needs a documentation heads-up that there's potential web server config considerations or... something.