Question

NOTE: I have completely rewritten this question to take into account new information. Please reread if you've already been through this one.

I'm getting errors when using a cfthread from within a custom tag in ColdFusion 10. In the Application log, I get the following entries:

Variable _cffunccfthread_cfThreadTag2ecfm16902001291 is undefined.

The name of the function it's returning as an error is _cffunccfthread_cf[Page Name Calling the CFThreadTag] then a number that doesn't change from request to request. I can duplicate this every time with the following code:

Application.cfc:

component
{
    this.name = "CFThreadCustomTagTest";
}

ThePage.cfm:

<cfthread action="run" name="ThreadTestInPage">
    <cflog log="Application" text="The thread in the page successfully ran" type="information" />
</cfthread>
<cf_ThreadTag />

ThreadTag.cfm:

<cfif thisTag.ExecutionMode EQ "start">
    <cfthread action="run" name="ThreadTest">
        <cflog log="Application" text="The thread within the tag successfully ran" type="information" />
    </cfthread>
</cfif>

Just drop all three files in a directory in ColdFusion 10 and load ThePage.cfm. I get the following entries in the Application log:

"Severity","ThreadID","Date","Time","Application","Message"
"Information","ajp-bio-8012-exec-1","06/19/12","07:18:11",,"C:\ColdFusion10\cfusion\logs\application.log initialized"
"Information","cfthread-11","06/19/12","07:18:15","CFTHREADCUSTOMTAGTEST","The thread in the page successfully ran"
"Error","cfthread-9","06/19/12","07:18:15",,"THREADTEST: Variable _cffunccfthread_cfThreadTag2ecfm16902001291 is undefined. "

I also noticed that in the error for the thread within the custom tag, it does not contain the application name. While the log entry for the thread in the page does. Notice that the error line simply has ,, for the Application column of the log, while the successful thread has "CFTHREADCUSTOMTAGTEST".

If I change ThreadTag.cfm to wait for the thread within the tag to finish processing, then everything works fine, and I get the two entries in the log as I expect:

<cfif thisTag.ExecutionMode EQ "start">
    <cfthread action="run" name="ThreadTest">
        <cflog log="Application" text="The thread within the tag successfully ran" type="information" />
    </cfthread>
    <cfthread action="join" name="ThreadTest" timeout="10" />
    <cfdump var="#cfthread#">

</cfif>

And to verify that there are no funky settings anywhere, here's my local development environment's settings summary.

So it seems that if I just throw the thread out there, and don't wait for it to finish, then the thread seems to be looking for something from the parent page that is no longer in memory. At least that's my completely unfounded guess :).

I've also filed a bug with Adobe. Bug number 3218452.

Was it helpful?

Solution

I understand your predicament, but there's no actual question here.

Basically you've found a bug in CF. A few people - myself included - can replicate it.

No-one's missing anything, except for the Adobe engineers who missed including this sort of thing in their regression testing when implementing CF10. That's no indictment of them, really, as I think this is reasonably edge case, perhaps?

The "variable" CF ain't finding is actually the name of the compiled class that the CF compiler makes when compiling the code. It looks like there's a compiler bug to me.

For example, my error is this: THREADTEST: Variable _cffunccfthread_cfThreadTag2ecfm13713410591 is undefined.

However the compiled class is: cfThreadTag2ecfm1371341059$func_CFFUNCCFTHREAD_CFTHREADTAG2ECFM13713410591.class

I don't know what part of the class name the variable is supposed to be named for, but I suspect it should be looking for func_CFFUNCCFTHREAD_CFTHREADTAG2ECFM13713410591. Or on the other hand the compiler should not be compiling the ThreadTag.cfm file as a FUNCTION? But I'm guessing... it might need to compile the thread code as a function so as to call it in a separate thread? That's a guess. Either way: it's compiling the code as one thing, and then looking for a different thing. because of a bug.

But bottom line here: yep, you've found a bug. And you've flagged it with Adobe. I dunno what else there is for you to do here?

So basically we now know one cannot have a <cfthread> call in a custom tag (I also tested via <cfmodule>: same problem). You're gonna have to write yer code a different way, using an include or a method or something. Less than ideal, I know, but what can you do?

Footnote: I looked at the compiled code and it looks like the problem is CF is compiling the class with that func_ prefix, but it's referring to it in its code without. I didn't follow the code all the way to checking everything that's happening, but it looks to me like there are references to it trying to load _cffunccfthread_cfThreadTag2ecfm13713410591 rather than the correct name: func_CFFUNCCFTHREAD_CFTHREADTAG2ECFM13713410591.class.

OTHER TIPS

Dan,

Please look on this page:

http://help.adobe.com/en_US/ColdFusion/10.0/Developing/WSc3ff6d0ea77859461172e0811cbec0b2e1-7ff0.html

And this section "Determining the tag execution mode"

And try the equivalent mode check code <cfswitch expression=#thisTag.ExecutionMode#>

To see if this causes a different compiler code gen. Maybe it will gen code a bit different and the variable will get generated.

Also, another test to try is to put you tag first in "ThePage.cfm" and see if that causes a different code gen as well.

Finally, are you on a newer JVM, as newer ones use the latest Fork/Join features of the Java concurrency approach such as Futures, etc. and they may be causing different code gen. Maybe set your JDK to an older one and see if the code gen is different.

No real answer, but some things to look at.

I ran into this as well.

My solution was to refactor and put the cfthread stuff into a .cfc and call that from the .cfm page.

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