Concurrency and scope issues when CFM is enabled from CFC

I put the component in the application area so that it is common to all requests, and it includes the cfm template:

<cfcomponent output="false"> <cffunction name="run" output="false" returntype="void"> <cfset var tmp = false/> <cftry> <cfinclude template="inc.cfm"/> <cfcatch> <cffile action="append" file="#ExpandPath("error.log")#" output="ERROR: #cfcatch.message#"/> </cfcatch> </cftry> </cffunction> </cfcomponent> 

The template that is included simply creates an array and checks the length of the array as it should be if it does not write the error.log file:

 <cfset tmp = [ "one", "two", "three" ]/> <cfif ArrayLen(tmp) neq 3> <cffile action="append" file="#ExpandPath("error.log")#" output="Length = #ArrayLen(tmp)#"/> </cfif> 

If I then run the load through it (100 simultaneous threads), I get the following items appearing in my error.log file ...

 ERROR: element at position 3 of array variable &quot;___IMPLICITARRYSTRUCTVAR0&quot; cannot be found. Length = 0 Length = 2 

Note I am using ColdFusion 9.0.1.274733 ontop for Java 1.7.0_09. I tested Railo on the same JRE and it works great.


In addition . There is also a problem modifying the tmp variable in the structure and adding a random element to the variables area that is not referenced anywhere ...

 <cfcomponent output="false"> <!--- Some random variable that does nothing with the exception of being the facilitator of my eternal pain ---> <cfset variables.t = {}/> <cffunction name="run" output="false" returntype="void"> <cfset var tmp = {}/> <cftry> <cfinclude template="inc2.cfm"/> <cfcatch> <cffile action="append" file="#ExpandPath("error.log")#" output="ERROR: #cfcatch.message#"/> </cfcatch> </cftry> </cffunction> </cfcomponent> 

Which includes a template very similar to the first one that looks like this ...

 <cfset tmp.arr = [ "one", "two", "three" ]/> <cfif ArrayLen(tmp.arr) neq 3> <cffile action="append" file="#ExpandPath("error.log")#" output="Length = #ArrayLen(tmp.arr)#"/> </cfif> 

If you delete an item in the variables , it works fine. If you dump #variables# and #local# in the template, everything will be where you expect it to be.


(Update from comments)

Since then I raised this problem as an error. # 3352462

+6
source share
3 answers

This is based on Peter / your own comments above.

There have been / are a few bugs with limited structure and structure, and since CF8 introduced the syntax. Adobe's approach to fixing them was a bit like whack-a-mole, rather than trying to figure out the problem once and correctly. Looks like you found another example of this. It would be interesting to know if this still exists in CF10, although, as I know, they fixed a few more during their dev loop.

The only way is not to use this notation in situations where you see these problems.

Could you raise a bug so that Adobe doesn't know about it?

Also a little noteworthy, but not related to your specific problem here: CF is not yet supported on Java 1.7. You can think about it.

+4
source

You might want to add some lock around your tag to allow only one request to modify the file.

0
source

In your first example, it doesn't matter if you declare tmp as an array instead of a boolean?

 <cfset var tmp = ArrayNew(1) /> 

instead...

 <cfset var tmp = false /> 
0
source

All Articles