Skip to main content
Ben Nadel at CF Summit West 2024 (Las Vegas) with: Eymard Ventura
Ben Nadel at CF Summit West 2024 (Las Vegas) with: Eymard Ventura

CFLock Name Is Case-Insensitive In ColdFusion

By
Published in

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:

Screenshot showing that second lock blocks and waits.

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

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel
Managed ColdFusion hosting services provided by:
xByte Cloud Logo