http://coldfusion.com logo
#cfml-general
Title
# cfml-general
j

Jim Partin

04/07/2022, 4:42 PM
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

Adam Cameron

04/07/2022, 4:42 PM
Can you give us a repro case, demonstrating the issue?
So we're all on the same page.
j

Jim Partin

04/07/2022, 4:45 PM
/**
* @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

Adam Cameron

04/07/2022, 4:46 PM
(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

Jim Partin

04/07/2022, 4:46 PM
Local Scope 2:
Local Scope 3:
a

Adam Cameron

04/07/2022, 4:46 PM
Also that's not very stand-alone. Is being in a CFC a requirement?
j

Jim Partin

04/07/2022, 4:47 PM
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

Adam Cameron

04/07/2022, 4:49 PM
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

Jim Partin

04/07/2022, 4:49 PM
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

Adam Cameron

04/07/2022, 4:52 PM
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

Jim Partin

04/07/2022, 4:54 PM
the mail is just to capture the state of local to verify it's busted
a

Adam Cameron

04/07/2022, 4:57 PM
It doesn't have any clutter. It just does close to the minimum to explicitly show there is a problem.
j

Jim Partin

04/07/2022, 5:03 PM
what bug fix?
a

Adam Cameron

04/07/2022, 5:04 PM
I had a bug in my sort callback
It was
return e2 - e2
; should have been
return e2 - e1
j

Jim Partin

04/07/2022, 5:04 PM
mmm
a

Adam Cameron

04/07/2022, 5:04 PM
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

Jim Partin

04/07/2022, 5:06 PM
well, at least i'm not crazy (in that there is a problem)
1
a

Adam Cameron

04/07/2022, 5:07 PM
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

Jim Partin

04/07/2022, 5:09 PM
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

Adam Cameron

04/07/2022, 5:14 PM
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

Jim Partin

04/07/2022, 5:17 PM
It doesn't even have to be set parallel within the function. any use of parallel map during the request will trigger it
a

Adam Cameron

04/07/2022, 5:17 PM
Maaaaaaaaaaaaaaark!!!!! @Mark Takata (Adobe) 😉
j

Jim Partin

04/07/2022, 5:27 PM
Appreciate the help with this, been bugging me for 3 days
👍 1
m

Mark Takata (Adobe)

04/07/2022, 5:40 PM
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

Jim Partin

04/21/2022, 3:14 PM
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

Mark Takata (Adobe)

05/11/2022, 4:22 PM
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
3 Views