Skip to main content
Ben Nadel at InVision In Real Life (IRL) 2019 (Phoenix, AZ) with: Jonas Bučinskas
Ben Nadel at InVision In Real Life (IRL) 2019 (Phoenix, AZ) with: Jonas Bučinskas

Adobe ColdFusion Bug: Nested Closures With Parallel Array Iteration Destroys Arguments

By
Published in

For the last two mornings, I've been trying to debug a very strange error in Big Sexy Poems. And, after several hours of attempting to isolate and reproduce the issue, I'm 95% sure that it's the same issue I ran into a year ago: Adobe ColdFusion Bug: Nested Array Iteration Breaks Closure Variables. But, this time the symptom is slightly different — it's not a closed-over variable that's being destroyed, it's the arguments. Which, looking back at my previous reproduction, is probably the same issue. But this gives me another thing to test once the bug is fixed, which is why I'm documenting it.

Good News: My filed bug, CF-4227716, is marked as fixed (in build 2025.0.06.331594) and should be released in the next update (hopefully). When that's released, I'll be able to test against both this isolated case and the one in my aforementioned post.

As with the previous blog post, the root of the issue starts with async iteration over an array. In the following isolated reproduction, I'm:

  1. Iterating over a collection of functions (not closures).
  2. Passing a closure out of scope.
  3. Invoking the out-of-scope closure.
  4. Referencing an argument passed along with the closure.

It's step 4 that breaks — the argument no longer exists when the root iteration is parallel (but works fine if the root iteration is performed in sequence). Also, step 3 - invoking the out-of-scope closure - is necessary to trigger the bug.

My reproduction case, still throwing errors in Adobe ColdFusion 2025.0.06.331564:

<cfscript>

	try {

		arrayEach(
			[ testFunction ],
			( test ) => test(),
			// ASYNC iteration causes the bug ("Variable OTHERARG is undefined.").
			true
		);

	} catch ( any error ) {

		writeDump( error );

	}

	// ------------------------------------------------------------------------------- //
	// ------------------------------------------------------------------------------- //

	private void function testFunction(string myArg = "") {

		invokeClosure(() => {
			// Closure here doesn't do anything except trigger bug.
		});

	}

	private void function invokeClosure(
		required any callback,
		string otherArg = ""
		) {

		// NOTE: If I don't invoke this closure, the dump works - the argument is still
		// defined ("otherArg"). But, when I call this, Adobe ColdFusion destroys the
		// arguments and the dump results in a null reference error ("otherArg").
		callback();

		writeDump( otherArg );

	}

</cfscript>

If we run this, we get the following error:

Variable OTHERARG is undefined.

In my previous post, I had mischaracterized this issue as the "closed over" variable being destroyed. But, in this case, we can see that this is not the case. The otherArg is not a closed-over variable — it's just another argument passed by value alongside the closure.

When the next Adobe ColdFusion 2025 update is released, I'll double-check to make sure this is fixed.

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