I’ve one word for you, just one word… frames.
Amazing how simple it is to completely bust the CFLOCK tag. First, you create a simple page that has frames and loads another page into each frame.
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="tue, 04 jan 2000 1:00:00 gmt">
<cfheader name="cache-control" value="no-cache, no-store, must-revalidate">
</head>
<frameset rows="1" cols="*,*">
<frame src="thread.cfm?id=1">
<frame src="thread.cfm?id=2">
</frameset>
</html>
Now for the code that is supposed to lock in the first frame, then release and then get picked up subsequently by the second frame.
<cfoutput>
<html>
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="expires" content="tue, 04 jan 2000 1:00:00 gmt">
<cfheader name="cache-control" value="no-cache, no-store, must-revalidate">
</head>
<body>
<cflock name="globallockthatbreaks" type="exclusive" timeout="10" throwontimeout="true">
#id#: got lock @ #timeformat(now(), "hh:mm:ss")#-#gettickcount()#<p>
<cflock name="globallockthatbreaks" type="exclusive" timeout="10" throwontimeout="true"/>
<cflock name="stall_out_#id#" throwontimeout="yes" timeout="1" type="readonly">
<cftry><cflock name="stall_out_#id#" throwontimeout="no" timeout="2" type="exclusive" /><cfcatch/></cftry>
</cflock>
#id#: give up lock @ #timeformat(now(), "hh:mm:ss")#<p>
</cflock>
</body>
</html>
</cfoutput>
If you run this simple code, you’ll see that the lock is not honored and the threads in each frame are run simultaneously.
6 Responses for "How CFLOCK doesn’t"
My guess is the second ‘globallockthatbreaks’ refers to the first (because it has the same name and type) and releases it because the tag is ended immediately (because of the /). In my opinion the result you’re seeing isn’t a big mystery.
Having said that, however, when I run the code, using CFMX 7.0.2, the lock is honored just fine. What version are you using?
I tidied up your code a bit:
- output a “start” flag before the first
- flushed all output so one can see what’s going on as it’s running.
- and put a pause in it so one could see the other frame actively waiting.
And – as Ruud says – it works fine for me (7.0.2.142559).
The premise itself is a bit faulty anyhow: CF has no way of knowing that these two requests are in frames, it just sees two requests. So the fact the two requests are being called from frames is irrelevant to anything you might experience, one way or the other.
–
Adam
Hm, this must have been fixed in the 7.0.2 release. I’m still using 7.0.
Ruud, funny how me seeing the results is not a mystery when you don’t see them :)
Adam, thanks for the input, but the premise isn’t faulty. You’re right that the frames are irrelevant, I simply chose that for simplicity. What I’m pointing out is that I’m seeing a GLOBAL lock not being honored. I doesn’t matter how the two requests are generated, the GLOBAL lock should be honored.
I’ll upgrade to 7.0.2 and test again.
Hi Steve.
Your PREMISE is this:
“I’ve one word for you, just one word… FRAMES.
Amazing how simple it is to completely bust the CFLOCK tag. First, you create a simple page that has FRAMES and loads another page into each FRAME.”
(my emphasis)
Are you telling me you’re NOT suggesting frames have something to do with it, given your statements above?
–
Adam
Hi (again) Steve
I tested on 7.0.0.91690 and indeed am seeing what you’re seeing.
I’m sending the messages to file instead of screen, so I can see what order they’re in, and – as Ruud alluded to – the inner “globallockthatbreaks” clears the “outer” one too. Although it’s got nothing to do with the “empty” tag: I would never run code with poorly-formed CFML tags, so expanded it out and added a message within the lock, and one still gets what you’re seeing.
Note that if the INNER “globallockthatbreaks” is readonly, not exclusive, then the issue does not occur.
I’m not sure this is a bug though, as I can’t find any reference to being able to nest locks. Although equally, I can’t see anything that one CAN’T either.
Bug or not: it’s good to know about.
Cheers.
–
Adam
Strange that the readonly lock doesn’t act the same, I didn’t try that one.
Point taken about my emphasis on frames, I was trying to be witty is all.
Leave a reply