Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.
Ben Nadel at CFUNITED 2008 (Washington, D.C.) with: John Mason
Ben Nadel at CFUNITED 2008 (Washington, D.C.) with: John Mason@john_mason_ )

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

By Ben Nadel on
Tags: ColdFusion

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!




Reader 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.

Reply to this Comment

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>

Reply to this Comment

@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!

Reply to this Comment

Post A Comment

You — Get Out Of My Dreams, Get Into My Comments
Live in the Now
Oops!
Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.