从CFC中包含CFM时的并发和范围问题

Stu*_*eld 6 coldfusion cfc coldfusion-9

我在我的应用程序范围中放置一个组件,以便在所有请求中共享它,它包含一个cfm模板:

<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>
Run Code Online (Sandbox Code Playgroud)

正在包含的模板只是创建一个数组并检查数组长度应该是什么,如果不是它写入error.log文件:

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

如果我然后在它上面运行一个加载(100个并发线程),我会在我的error.log文件中出现以下项目...

ERROR: element at position 3 of array variable &quot;___IMPLICITARRYSTRUCTVAR0&quot; cannot be found.
Length = 0
Length = 2
Run Code Online (Sandbox Code Playgroud)

注意我在Java 1.7.0_09上使用ColdFusion 9.0.1.274733.我在相同的JRE上测试过Railo并且工作正常.


附加以下还会导致问题,将tmp变量更改为结构并在variables范围中添加随机项,而不是在任何地方引用...

<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>
Run Code Online (Sandbox Code Playgroud)

其中包含一个与第一个非常相似的模板,看起来像这样......

<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>
Run Code Online (Sandbox Code Playgroud)

如果您删除variables范围中的项目,它可以正常工作.如果你转储#variables##local#在模板中,一切都是你期望的.


(评论更新)

我已经把这个问题提到了一个bug#3352462

Ada*_*ron 4

这是基于彼得/您自己的上述评论。

自 CF8 引入语法以来,数组和结构简写概念一直存在许多错误。Adobe 解决这些问题的方法有点像打地鼠,而不是一次性正确地解决问题。看来您已经找到了另一个这样的例子。看看 CF10 中是否仍然存在这一点会很有趣,因为我知道他们在开发周期中修复了更多内容。

解决这个问题的唯一方法是在遇到这些问题的情况下不要使用该表示法。

您能否为此提出一个错误,以便 Adob​​e 意识到这一点?

另外还有一点值得注意,但与您的具体问题无关:Java 1.7 尚不支持 CF。你可能想记住这一点。