0

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">
pmascari
  • 271
  • 2
  • 10
  • 1
    can you post some code so we can reproduce the issue ourselves? – Matt Busche Jul 05 '13 at 21:13
  • Also, take a look at the exception logs CF generates, as that may point you at a line of code. Also, using Fiddler or Chrome dev tools, take a look at the HTTP response when you run the function outside of CFTHREAD and see if any other headers do get set – barnyr Jul 05 '13 at 21:18
  • I updated the post with code. I also looked in the logs and can't find anything referring to this error. – pmascari Jul 08 '13 at 13:13
  • That cflocation is only after the thread in the code - the thread runs asynchonously with it (and will likely finish after it has executed, and thus after the response has been sent back); it is irrelevant and not the cause. – Peter Boughton Jul 08 '13 at 13:17
  • 1
    The error message is pretty explicit and seems to be what Henry says, so look inside `buildReport` - it'll contain (or be calling some other code that contains) a cfheader or another cflocation or some other equivalent construct which is attempting to set a HTTP header. – Peter Boughton Jul 08 '13 at 13:18

2 Answers2

5

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

Henry
  • 32,689
  • 19
  • 120
  • 221
  • Updated the post with code. To be clear...the code in the thread simply creates and save a PDF to the server. It is not meant to interact with a browser at all. I see nothing in the logs regarding this error – pmascari Jul 08 '13 at 13:13
  • 1
    _"It is not meant to interact with a browser at all"_ - and yet the error says it is trying to do so. Since you say it's saving a PDF (that info should be in the question), I wouldn't be surprised if there's an (incorrect/unnecessary) cfcontent in there somewhere. – Peter Boughton Jul 08 '13 at 13:21
  • 1
    Found it. Scoured through the code and found a random CFHEADER tag above one of the CFDocument tags. – pmascari Jul 15 '13 at 20:04
0

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

pmascari
  • 271
  • 2
  • 10