Anyone ever run into local scope corruption within...
# cfml-general
j
Anyone ever run into local scope corruption within a cfc in cf21 when using ArrayMap in parallel mode, followed by an ArraySort? By local scope corruption, I mean that the local scope is now based off the ArraySort closure, outside of the closure, so that function level variables are no longer seen
a
Can you give us a repro case, demonstrating the issue?
So we're all on the same page.
j
/**
* @output false * @accessors false **/ component{ /** * @output false **/ public Foo function init(){ return this; } /** * @output false **/ public array function doThing(){ return doThing2(); } /** * @output false **/ private array function doThing2(){ cfmail( from="debug@localhost", to="debug@localhost", subject="Local Scope 1", type="html" ){ WriteDump( var=Local, showUDFs=false ); }; Local.aValuesIn = [ "a", "b", "c", "d", "e" ]; Local.aValuesOut = Local.aValuesIn.map( function( item ){ switch( item ){ case "a" : { return new Bar( 1 ); } break; case "b" : { return new Bar( 2 ); } break; case "c" : { return new Bar( 3 ); } break; case "d" : { return new Bar( 4 ); } break; case "e" : { return new Bar( 5 ); } break; } }, //enable parallel to break code true, 5 ); cfmail( from="debug@localhost", to="debug@localhost", subject="Local Scope 2", type="html" ){ WriteDump( var=Local, showUDFs=false ); }; Local.aValuesOut.sort( function( e1, e2 ){ return compare( e1.getId(), e2.getId() ); } ); cfmail( from="debug@localhost", to="debug@localhost", subject="Local Scope 3", type="html" ){ WriteDump( var=Local, showUDFs=false ); }; return Local.aValuesOut; } }
a
(normally a big wodge of code like that would be better in a trycf gist or just a normal gist rather than inline, but cool
j
Local Scope 2:
Local Scope 3:
a
Also that's not very stand-alone. Is being in a CFC a requirement?
j
yes
i can zip up the other files (an empty generic application.cfc, an index.cfm, and bar.cfc which just has the id property)
a
If yer repro code poss requires zipping, it's not been pared back enough to just be a repro case, I think. I mean that code has a cfmail call in it?! How is that necessary to reproduce the situation?
j
the cfmail is to debug the error. by the end of the code, return Local.aValuesOut fails because Local.aValuesOut doesn't exist in the Local scope bc Local is stuck within the arraySort
but only if the arrayMap is run in parallel mode
a
My point is your repro case should only include code necessary to demonstrate the issue. Nothing more. Nothing less.
If there's a mail call in your repro case, that implies it has something to do with the problem
j
the mail is just to capture the state of local to verify it's busted
a
It doesn't have any clutter. It just does close to the minimum to explicitly show there is a problem.
j
what bug fix?
a
I had a bug in my sort callback
It was
return e2 - e2
; should have been
return e2 - e1
j
mmm
a
anyway, that reproduces your problem. And anyone can just click "run" to see it
(and compare with Lucee to see the correct behaviour, etc)
I'd search the bug tracker, but this seems pretty edge-case-y to me, so doubt anyone else has spotted it!
j
well, at least i'm not crazy (in that there is a problem)
1
a
Seems to be peculiar to
sort
. Similar code using
reduce
is fine
I suspect it's a quirk of
sort
(incorrectly, IMO) actually updating the initial array, rather than returning a new one. That is different from how the other higher-order functions work, I think.
j
I've run into this issue a few times, recently, finally decided to track it down
funny thing is, turn off the parallelization of map in my code, and Things Just Work(tm)
a
yeh I noticed that. I don't really see how that should even possibly contribute to it. But... erm... it doesn't surprise me of how ColdFusion has implemented higher order functions and function expressions etc.
Ooh, and it is related to that sort callback being a function expression. Problem does not exist if using a function defined via statement: https://trycf.com/gist/eb5b7a0f97f4e7b4669a68c7ac3f49d7/acf2021?theme=monokai
so it's messing up its closure bindings.
j
It doesn't even have to be set parallel within the function. any use of parallel map during the request will trigger it
a
Maaaaaaaaaaaaaaark!!!!! @Mark Takata (Adobe) 😉
j
Appreciate the help with this, been bugging me for 3 days
👍 1
m
Well that one is... wow. Quite a bug. I think you're correct btw, there's some kind of call behind the scenes that is borking up (technical term) the scopes. Lemme send this in with the two other things I found yesterday 😛
OK well I would ask you to post a bug, but (ironically) I just tried tracker and... um, it is broken. So, hold a sec while I figure out what went wrong this time with it lol.
j
Did this ever get put into the bug tracker? I'm eagerly excited for the next patch to resolve this so I can clean up a bunch of code
I see there is an update 4 for 2021, @Mark Takata (Adobe), were you ever able to get this issue into the bug tracker? I wanted to see if it got resolved :)
m
Jim, this update was security-only. We are trying to separate the patches from now on whenever possible. The bug fix patch should be coming soon, I'll check to see if it got in that.
❤️ 1