Question

I'm getting a weird error from CFThread. I have it wrapped around a function that runs perfectly when outside CFThread. But, it takes about 20 seconds to complete so I shoot it off to CFThread then CFLocation the user to a new page and alert them when it's done.

It's also wrapped in CFTRY to email me should there be a problem.

I'm getting emails where the CFCATCH.Message is:

"CFThread failed to set header to response as request had already completed"

I can't find any reference to an error like this on Google. I'm assuming it's not liking the fact that I'm using CFLocation directly after invoking the Thread. So, for the hell of it, I tried using a META REFRESH to redirect the user instead. Same error result.

Any ideas?

UPDATED 7/8/13:

Code here:

<cfset admsID = replace(createUUID(),"-","","all")>
<cfthread action="run" name="runADMS#admsID#" admsID="#admsID#" formstruct="#form#">
<cftry> 
<cfobject component="cfc.AutoDealerBrandMarketShare" name="adms">
<cfset rptPDF = adms.buildReport(dealer=formstruct.chosenDealer,mkt=formstruct.DMACode,make=formstruct.Make,rptID=admsID)>
<cfcatch type="any">
<cfmail to="pmascari@mysite.com" from="techsupport@mysite.com" subject="ADMS Error">
Error occurred running a Polk Auto Dealer Market Share report.
#cfcatch.Message#
#cfcatch.detail#
</cfmail>
</cfcatch>
</cftry>
</cfthread> 
<cflocation url="http://www.usercanwaithere.com">
Was it helpful?

Solution

If you think about it, it makes sense because cfthread can be still running After the respond has been sent to the client. Therefore, setting something new in header does not make sense anymore 'cause the "ship has sailed".

As you know, CFThread allows you to spawn a new thread do some processing in parallel with the request. This thread can continue to run even after the request has completed. Since this thread is not connected to the HTTP request that spawned it, any operation done from the thread which tries to change something in the HTTP request/response - like setting header, cookie, response code etc would not make sense and should not be done.

So one should not use cfcookie, cfheader, cfcontent etc inside cfthread as it can cause unpredictable behavior.

-- Rupesh Kumar, Adobe ColdFusion engineer

OTHER TIPS

Found it. Scoured through the code and found a random CFHEADER tag above one of the CFDocument tags.

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