CFLock Name Is Case-Insensitive In ColdFusion
This is a quick sanity check to see if the name attribute of the CFLock tag is case-sensitive in ColdFusion. I've never thought about this since my application code is always in control of the lock names. However, I do sometimes have a workflow in which the name attribute is partially driven by the URL scope. Which means that — in rare cases — part of the name attribute is "technically" considered user-provided content.
To test this, I created two templates that attempt to acquire an exclusive lock on the same name. In one template, the lock name is all uppercase (NAME-CASING-TEST):
<cfscript>
lock
name = "NAME-CASING-TEST"
type = "exclusive"
timeout = 30
{
sleep( 10 * 1000 );
}
</cfscript>
And, in the other template, the same lock name is all lowercase (name-casing-test):
<cfscript>
startedAt = getTickCount();
lock
name = "name-casing-test"
type = "exclusive"
timeout = 30
{
writeOutput( "Lock acquired in... #( getTickCount() - startedAt )#ms" );
}
</cfscript>
With these two templates in place, I then invoke the first one followed quickly by the second one. If the name attribute is case-sensitive, both locks should be acquired immediately. However, if the name attribute is case-insensitive, the second lock will have to block-and-wait for a few seconds while the first lock finishes its sleep() command.
And so, when we run this experiment, we get the following output:
When the two CFML templates are run concurrently, the second one has to block-and-wait for the first one to finish sleeping:
Lock acquired in... 8,713ms
This confirms that the CFLock tag's name attribute is case-insensitive.
Want to use code from this post? Check out the license.
Reader Comments
Post A Comment — ❤️ I'd Love To Hear From You! ❤️
Post a Comment →