coldfusion - 为什么具有无限循环的请求不会被 ColdFusion 请求超时杀死?

标签 coldfusion infinite-loop

首先,我将 Timeout Requests after (seconds) 设置为 20在 CF 管理员中。

然后我用类似 while(true); 的行运行 cfm

该页面将运行超过 20 秒,并且在我写这篇文章时该线程仍然存在。

以下是使用 Server Monitor 拍摄的快照

Thread  jrpp-3 request type - TEMPLATE REQUEST
*Template Path - D:\Projects\infiniteLoop.cfm
*Request Parameters - {}
*Request Method - GET
*Client IP address - 127.0.0.1
*Thread elapsed time - 322659 milliseconds

这正常吗??这是CF9.0.1.,开发者版。
多实例设置,使用 JRun。

停止无限循环的唯一方法是重新启动CF。

最佳答案

ColdFuison 中的请求超时不会以您期望的方式运行。他们以这种方式呈现,你会想象有一个看门狗,它检查你的请求已经运行了多长时间,并在请求超时时或之后立即杀死它。
实际出现的情况是,只有在运行某些标签时,CF 才会检查请求的耗时是否超过设置的限制。 <cfoutput>是它检查的标记之一,这就是为什么您经常看到指向 cfoutput 的超时超时消息,即使您知道执行时间不会很长。

<cfsetting requesttimeout="5" enableCFoutputOnly="no" />

<!--- Looping with a condition <cfloop blamed --->
<cfset request.counter=0 />
<cfloop condition="true">
    <cfset sleep(1000) />
    <cfset request.counter=request.counter+1>

    <cflog file="timeout" text="#request.counter#">

    <cfif request.counter GT 8>
        <cfbreak>
    </cfif>

</cfloop>

<!--- Looping with an index, times out, naming CFLOOP as the offending tag --->
<cfloop index="foo" from="1" to="8">
    <cfset sleep(1000) />
</cfloop>

<!--- Looping with an index, times out, naming CFOUTPUT as the offending tag --->
<cfloop index="foo" from="1" to="8">
    <cfset sleep(1000) />
    <cfoutput>Hello</cfoutput>
</cfloop>


<!--- Same loop, but in script. No timeout warning at all --->
<cfscript>
for(foo=1;foo<=8;foo++){
    sleep(1000);
}
</cfscript>

<!--- Same loop, now with WriteOutput() called. Still no timeout --->
<cfscript>
for(foo=1;foo<=8;foo++){
    sleep(1000);
    writeoutput("tick...");
}
</cfscript>

上面的代码显示了 requesttimeout 的一些奇怪行为。正如 Mark Kruger 指出的那样,对外部资源的任何调用都意味着不检查超时,而且我猜测只是执行您自己的逻辑的大块脚本也不会被检查,从而导致下一个输出语句受到指责。

如果您需要跟踪代码滞后的位置并且超时消息指向错误的位置,我会在长时间运行的代码运行时使用日志记录或 jstack 从服务器获取堆栈跟踪。间隔几秒钟抓取一些堆栈跟踪,然后通过 Samurai 运行日志文件找到代码在做什么。

关于coldfusion - 为什么具有无限循环的请求不会被 ColdFusion 请求超时杀死?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10508534/

相关文章:

ColdFusion 从 GetHttpRequestData().headers 检索接受语言时出错

jquery - ColdFusion,如何将字符串转换为数组?

excel - 如何使用 Coldfusion 创建 xlsx 文件

javascript - jQuery 和 Ajax 仅对第一个元素使用react!

variables - 在 Coldfusion8 application.cfc 中哪里定义应用程序和 session 变量?

javascript - 当我运行这段 Javascript 代码时,为什么我的浏览器总是崩溃?

c++ - cout 在无限循环的情况下不起作用

打开时尚未选择 VB.NET 窗体

Android 蓝牙连接错误(未找到 bt sock,scn 1)-无限循环

java - 多种方法和无限循环发生的问题