Question

I’ve been battling with a bug with cflocation ever since I upgraded from CF9 to CF10. I’ve worked on it a number of times but always give up but today it’s finally annoyed me enough that it’s time to solve the problem (I hope).

Firstly, apologies as I have tried to write a simple test case to reproduce this problem but so far I’ve been unable to reproduce it outside of original code.

I have a multi-step import process that should run overnight. The process is made up of about 10 files that chain together. When calling the process via a scheduled task a URL parameter (scheduledtask) is also passed. If the parameter does not exist, at the end of each step it stops and waits for the user to click a link to the next step. If the parameter does exist it uses cflocation to move to the next step.

Of all the steps, the 2nd one is the most complex and time consuming (data from multiple web service requests that then need joining, cleaning and inserting into a database). It’s this second step that has a problem after moving to CF10. The page seems to work fine as it’s getting to the very bottom of the page where the cflocation tag is but it never fires cflocation. I’ve added in a cfmail tag to email me as the cflocation is being called, which is always sent, but again cflocation doesn’t fire.

It can’t get much more basic than:

<cfif scheduledtask EQ "true">
   <cfmail from="xxxxx” to="xxxx” subject="About to call duplicate" type="text/html"> 
      <p>calling duplicate check - scheduledtask</p>
   </cfmail>

   <cflocation url="importDupCheck.cfm?scheduledtask=true" addtoken="false">
</cfif>

I know that there is a problem with cfflush and cflocation and I’ve already checked for that.

As a test I tried moving the above logic up the page to just after all the data is retrieved by the webservice but before it’s processed and this time the cflocation worked. I thought maybe it’s a timeout problem where the scheduled task engine has given up waiting even though the page is being allowed to fully load. I tried testing this by having a basic file that had:

<cfset sleep(240000)>
 * 4 minutes

before it called cflocation but it worked fine.

The other steps in the process are working as expected with cflocation, just not this one. All this code runs fine under CF9, just failing with CF10.

Does anyone has some pointers on where I should be looking?

Regards Mark


* Update * So I’ve now worked out how to easily reproduce this in a few lines of code. Turns out it has nothing to do with scheduled tasks.

index.cfm

<h1>Testing cflocation</h1>

<cfloop index="i" from="1" to="7000" ><!--- For me it stops working once the loop goes beyond 6808 rows --->
    row <cfoutput>#i#</cfoutput>: abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789<br/>
</cfloop>

<p>Now loading resultpage via cflocation</p>
<cflocation url="resultpage.cfm" addtoken="false">

resultpage.cfm

<h1>Made it!</h1>
<p>Reload the <a href="index.cfm">first page</a></p>

In my testing I found that if I looped 6808 times it works but 6809 times fails. With 7000 records we are only talking about a 36 KB file….why is this failing only in CF10?

One last thing I should note in case it has an impact- everything I do is done via https.

Was it helpful?

Solution

Ok I worked it out

In CF Administrator

Maximum Output Buffer size 1024

After which a flush will occur which will stop cflocation working.

Increase it and it works.

OTHER TIPS

I have no idea why your code as it stands doesn't work, I'm afraid. At a guess, it's down to ColdFusion 10's replacement of the scheduled task engine, and it not liking some vagary of client-side redirects.

However maybe you can bypass the situation anyhow.

ColdFusion 10's scheduler has a concept of chaining tasks, so that when a task finishes, another one is kicked off. You could conceivably revise your scheduler to leverage that instead?

I had a similar issue, but I was using the location() function in a cfscript. But I suspect the same principle applies.

Prior to the location() function, we were calling a function that was not wrapped in <cfsilent> tags. As a result, every line of the function, including loops, was being output as an empty line of HTML. When I viewed the source code, there were over 20,000 lines of empty HTML code. That is probably enough to reach the 1024 kb buffer limit and trigger the flush that aborts the redirect.

By adding <cfsilent> tags to the custom function, I reduced the number of empty lines of HTML to 39, and now the location() function works as expected.

To determine if this is the issue you are having, add abort; (or <cfabort>) just ahead of the location(), then view the source code of the resulting - presumably empty - page.

Have you tried adding CFABORT after CFLOCATION? That's what I always do - as the code after CFLOCATION should not be executed.

If you check the response from the server (using Charles proxy, Fiddler or something similar) you may find something in the HTML/JS that's preventing the redirection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top