Skip to main content
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Jeff McDowell and Joel Hill and Jonathan Rowny and Shawn Grigson and Jonathan Dowdle and Matt Vickers and Christian Ready and Asher Snyder and Clark Valberg and Oscar Arevalo and David Bainbridge and Josh Siok
Ben Nadel at cf.Objective() 2014 (Bloomington, MN) with: Jeff McDowell Joel Hill Jonathan Rowny Shawn Grigson Jonathan Dowdle Matt Vickers Christian Ready Asher Snyder Clark Valberg Oscar Arevalo David Bainbridge Josh Siok

Odd Error Involving CFThread, WriteDump(), Format Text, CFSaveContent And ColdFusion 10

By
Published in Comments (4)

Yesterday, I happened upon a really odd bug in ColdFusion 10. I point out ColdFusion 10 as this seems to work just fine in ColdFusion 11; so, if you're on 11, feel free to ignore. The error only occurs in a extremely specific context: Using the writeDump() method with format="text" inside a CFSaveContent block inside CFThread. And, it only occurs if you call the writeDump() method more than once in the same thread.

To see this in action, take a look at the following code:

<cfscript>

	// Initiate a thread.
	thread
		name = "testThread"
		action = "run"
		{

		// Capture the output of writeDump() in a buffer.
		savecontent variable="thread.resultA" {

			writeDump( var = "a", format = "text" );

		}

		// Capture the output of writeDump() in a buffer.
		// --
		// NOTE: We have to do this TWICE - it won't error if you only do it once.
		savecontent variable="thread.resultB" {

			writeDump( var = "b", format = "text" );

		}

	} // END: Thread.


	// Wait for the threads to come back so we can see the output.
	thread action = "join";

	// Output our thread so we can see the Error object.
	writeDump( cfthread.testThread );

</cfscript>

As you can see, I'm making two different calls to writeDump(), with format="text", inside a CFSaveContent output buffer with format="text". And, when we run the above code, we get the following thread error:

Attribute validation error.The tag requires the attribute var.

And, here's the entire Thread output:

Using writeDump() inside CFSaveContent inside CFThread, weird bug.

As you can see, the "resultA" key made it safely into the output; this is because the error only occurs during the second invocation of writeDump().

This works fine if you don't use format="text". It also works fine if you're not inside a CFSaveContent block. It also works fine if you're not inside a CFThread context.

To fix this (for the code I was working on), I moved the writeDump() into a ColdFusion component. This fixed the issue, which I believe was some sort of confusion over local scoping. Super odd bug, though!

Want to use code from this post? Check out the license.

Reader Comments

7 Comments

@Ben,

I believe this is a bug i filed with adobe shortly after cf10 was released. It had to do with scope changing not working correctly inside a thread.

https://bugbase.adobe.com/index.cfm?event=bug&id=3521203

They addressed it by saying upgrade to CF11. (long after we filed the bug.)

The worst part was the way they refused to run cf from the command line to reproduce it in the way specified in the ticket and forced me to write a different reproduction script to get the bug to happen using cflog rather than cfdump.

7 Comments

BTW. the solution we went with in production was ridiculous.

file 1 "fixthread.cfm" (in the custom tag path) contents:
------------------------

<cf_fixthread2 />
<cf_fixthread2 />

------------------------

file 2 "fixthread2.cfm" is an empty file.

Then as the first line in any cfthread call is <cf_fixthread>

15,848 Comments

@Tom,

Super funky stuff! I tried to search the bug-base for things related to CFDump, but didn't see anything matching. But, yeah, it seems like it might be something related to scopes getting messed up.

I had to use a work-around like you - I moved the block of code into a totally different CFC. Then, I could call that from within the Thread and it seems to work properly. So weird!

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