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

CFLock not throwing exception

New Here ,
Jan 24, 2024 Jan 24, 2024

Copy link to clipboard

Copied

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>  


 

Views

148

Translate

Translate

Report

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.

Votes

Translate

Translate
Advocate ,
Jan 25, 2024 Jan 25, 2024

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

You're welcome. Glad to help. 🙂

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

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> 

 

 

 

Votes

Translate

Translate

Report

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

Copy link to clipboard

Copied

LATEST

Thanks BKBK,
I got it!

Votes

Translate

Translate

Report

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
Documentation