cflock do not throw timeout for same url called in same browser

Posted by Pritesh Patel on Stack Overflow See other posts from Stack Overflow or by Pritesh Patel
Published on 2013-10-17T09:50:08Z Indexed on 2013/10/18 21:56 UTC
Read the original article Hit count: 225

Filed under:
|
|
|
|

I am trying lock block on page test.cfm and below is code written on page.

<cfscript>
writeOutput("Before lock at #now()#");
lock name="threadlock" timeout="3" type="exclusive"
{
    writeOutput("<br/>started at #now()#");
    thread action="sleep"  duration="10000";
    writeOutput("<br/>ended at #now()#");
}
writeOutput("<br/>After lock at #now()#");
</cfscript>

assuming my url for page is http://localhost.local/test.cfm and running it on browser in two different tabs. I was expecting one of the url will throw timeout error after 3 second since another url lock it atleast for 10 seconds due to thread sleep. Surprisingly I do not get any timeout error rather second page call run after 10 seconds as first call finish execution.

But I am appending some url parameter (e.g. http://localhost.local/test.cfm?q=1) will throw error. Also I am calling same url in different browser then one of the call will throw timeout issue.

Is lock based on session and url?

Update Here is output for two different cases:

Case 1:

TAB1 Url: http://localhost.local/test/test.cfm

 Before lock at {ts '2013-10-18 09:21:35'} 
 started at {ts '2013-10-18 09:21:35'} 
 ended at {ts '2013-10-18 09:21:45'} 
 After lock at {ts '2013-10-18 09:21:45'}

TAB2 Url: http://localhost.local/test/test.cfm

Before lock at {ts '2013-10-18 09:21:45'} 
started at {ts '2013-10-18 09:21:45'}
ended at {ts '2013-10-18 09:21:55'} 
After lock at {ts '2013-10-18 09:21:55'}

Case 2:

TAB1 Url: http://localhost.local/test/test.cfm

 Before lock at {ts '2013-10-18 09:27:18'} 
 started at {ts '2013-10-18 09:27:18'} 
 ended at {ts '2013-10-18 09:27:28'} 
 After lock at {ts '2013-10-18 09:27:28'}

TAB2 Url: http://localhost.local/test/test.cfm? (Added ? at the end)

Before lock at {ts '2013-10-18 09:27:20'} 
A timeout occurred while attempting to lock threadlock.
The error occurred in C:/inetpub/wwwroot/test/test.cfm: line 13
11 : 
12 : <cfoutput>Before lock at #now()#</cfoutput>
13 : <cflock name="threadlock" timeout="3" type="exclusive">
14 :    <cfoutput><br/>started at #now()#</cfoutput>    
15 :    <cfthread action="sleep"  duration="10000"/> 
...

Result for case 2 as expected.

For case 1, strange thing I just noticed is tab 2 output "Before lock at {ts '2013-10-18 09:21:45'} indicates that whole request start after 10 seconds (means after the complete execution of first tab) when I have fired it in second URL just after 2 seconds of first tabs.

© Stack Overflow or respective owner

Related posts about coldfusion

Related posts about locking