Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFLock not throwing exception

New Here ,
Jan 24, 2024 Jan 24, 2024

Why does the following code not throw an exception when timeout is exceeded?
CF Admin "Timeout Requests after seconds" is checked and set to 2 seconds.


<cftry> 
  <cflock scope="application" type="exclusive" timeout="2" throwontimeout="yes">
    <cfset sleep(3000)>
  </cflock>
  <cfcatch type="any">  
  <h1>My Exception</h1>  
    <cfdump var="#cfcatch.type#"> 
    <cfdump var="#cfcatch.Message#"> 
  </cfcatch>
</cftry>  


 

537
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advocate , Jan 25, 2024 Jan 25, 2024

No exception is thrown because the timeout is for acquiring the lock, not what is being protected by the locked.

In your example, the lock has been successfully acquired when execution reaches the sleep() function.

Translate
Advocate ,
Jan 25, 2024 Jan 25, 2024

No exception is thrown because the timeout is for acquiring the lock, not what is being protected by the locked.

In your example, the lock has been successfully acquired when execution reaches the sleep() function.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 25, 2024 Jan 25, 2024

Thanks Eddie,
I misconstrued "Aquiring the lock".
Makes sense now.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Jan 25, 2024 Jan 25, 2024

You're welcome. Glad to help. 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 26, 2024 Jan 26, 2024

Anyway, you have to test it not with one request thread, as you have done. But instead with at least 2 separate request threads. That is because we are in the application scope.

 

We would then have a test where one request-thread waits on another. For example, test with page1.cfm and page2.cfm as follows. Launch page1.cfm then, within several seconds, launch page2.cfm.

 

<!--- page1.cfm --->
<h2>
	Sleep it off!
</h2>
<cflock scope="application" type="exclusive" timeout="30" throwontimeout="yes">
	<cfset sleepItOff()>
</cflock>

<cffunction name="sleepItOff">
	<!--- A good, long sleep! --->
	<cfset sleep(30000)>
</cffunction>
<!--- page2.cfm --->
<cftry> 
<cfset requestStartTime=getTickCount()>
<!--- You will have to wait for application that sleeps for 30 seconds --->	
<cflock scope="application" type="readonly" timeout="2" throwontimeout="yes">
	<cfset getIt()>
</cflock>

<cfcatch type="any">  
	<h1 style="color:purple">
	<cfoutput>Request waited for #(getTickCount() - requestStartTime)/1000# seconds</cfoutput>
    </h1>
	<h1>My Exception:</h1>  
	<cfdump var="#cfcatch#"> 
</cfcatch> 
</cftry> 

<cffunction name="getIt">
  	<cfreturn "It">
</cffunction> 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 26, 2024 Jan 26, 2024
LATEST

Thanks BKBK,
I got it!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources