Error: 'Response buffer is already flushed' on a CFlocation tag

I’ve migrated a site from CF to Lucee. I have a page that is running a CFEXECUTE command. Once it’s run, I then run a CFLOCATION to revert the user to a previous page.

I get the error Response Buffer is already flushed when running the CFLOCATION command. Here is the CFML:

I’m using this sort of command structure throughout this site (e.g. CFLOCATION tags with fueseactions, variables and messages that are then displayed on the forwarded page), so am not sure why this error should occur against this type of command.

Any ideas appreciated! Thanks.

OS: Windows Server 2022 Standard
Java Version: 11.0.18 (Eclipse Adoptium) 64 bit
Tomcat Version: 9.0.71
Lucee Version: 5.3.10.120

Cfexecute is an interaction between ColdFusion and the Operating System. So, it just might be that cfexecute and cflocation are not working well together.

What about using a named lock to synchronize them? For example, by doing something like the following:

lock name=“uniqueLockName68264” {
// the cfexecute code
}

lock name=“uniqueLockName68264” {
// the cflocation code
}

Hmm, I’ll investigate that one

You could try wrapping the cfexecute in a cfsilent

PS: that version of Lucee is old and subject to a CVE

Thanks for the response. I can give that a try, but I was more interested to find out why a tag like CFLOCATION would give such an error.

Yes, I saw about the CVE earlier today, so I’ll allocate some time to update the server.

so if you read the docs, unless you specify a variable or output file, the result is written to the current request <cfexecute> :: Lucee Documentation

OK. Am afraid that does not make much sense to me, but what I take away from this is that I was correct in thinking that it was an earlier CFEXECUTE that is causing a problem further on in the page. Right?

For now, I’ve added an outputfile argument to the CFEXECUTE and will report back if this fixes it.

Thanks"

Am afraid that does not make much sense to me

For cflocation to work, the server must send an HTTP location header to the browser. As the name implies, headers are the first thing to be returned by the server, before the actual response body is returned to the browser.

Lucee (like most other servlets) uses an output buffer that captures the output generated by your page and returns this output to the browser each time the buffer is full.
A common buffer size would be 1024 bytes, for example (I don’t know the actual default output buffer size used by Lucee).
When the buffer is full, the headers are sent to the browser (if they haven’t already been sent), followed by the buffer content.
This means that cflocation can only be used before Lucee’s output buffer has been filled and flushed for the first time. That’s because at that point, the headers are sent to the browser and there is no way to change the headers after the fact by your cflocation invocation.
So basically you need to call cflocation before too much output (even whitespace) has been generated by your page.

That’s why Zack suggested using cfsilent for the code preceding your cflocation call or using the variable attribute in order to prevent cfexecute’s output from being appended to the output buffer.
Hope this helps.