Adobe ColdFusion Bug: Nested Closures With Parallel Array Iteration Destroys Arguments
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:
- Iterating over a collection of functions (not closures).
- Passing a closure out of scope.
- Invoking the out-of-scope closure.
- 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 →