framework-one / fw1

FW/1 - Framework One - is a lightweight, convention over configuration, MVC application framework for ColdFusion / CFML.
http://framework-one.github.io
Other
374 stars 141 forks source link

ColdFusion 2016, passing in local scope cause CPU go up 100% #490

Closed peterpham closed 7 years ago

peterpham commented 7 years ago

I recently set up ColdFusion 2016 on Windows 2012 R2 on AWS EC2 using this AIM https://aws.amazon.com/marketplace/pp/B071X7DB7M

In my default view, I called another subview and pass in local as args. The code in main/default.cfm looks like this

<cfoutput>
#now()#
<br />
#view(path = 'main/subview', args = local)#
</cfoutput>

This caused CPU went up 100% and entire server stop (even ColdFusion Admin does not respond). I reckon there was an endless loop somewhere - probably Java recursion. Upon close inspection, this is where it most likely happening

private string function internalView( string viewPath, struct args = { } ) {
...
structAppend( local, args );
...
}

Somehow, using structAppend(local, args) where args, again, is another local scope - had caused ColdFusion stop responding. I tested with both FW/1 version 2.5 and FW/1 version 4.0. This happened in both versions.

This might be most likely a ColdFusion2016 bug. But just wonder if anyone experienced the same?

seancorfield commented 7 years ago

Use jstack or similar to get a stacktrace from the CF process -- that will show what's going on in the code (and whether indeed your supposition is correct).

Given ACF's record with weird local scope bugs, it wouldn't surprise me.

As a potential workaround, in your default view, instead of passing local as args, do this:

<cfset var viewArgs = {} >
<cfset viewArgs.append( local ) >
 #view( path = "sub/view", args = viewArgs )#

It would likely also be worth your while trying this on Lucee to see if the same problem occurs.

peterpham commented 7 years ago

Thanks @seancorfield I have tried it, didn't help either. I also tried using duplicate(local), it does not work either.

I can confirm that it appears to be an CF2016 bug rather than FW/1 related as I can replicate the same use case without framework. The local scope inside a template called by cfinclude inside a function appears to cause this acting up.

A bit weird that this CF2016 has been released for a while and FW/1 is rather popular in CF but no one reported anything yet. I used a freshly new installed ColdFusion2016 so may have to try again on a different instance again to see if I can reproduce same result.

Anyway, I close this issue for now as nothing you can do.

seancorfield commented 7 years ago

I guess folks don't pass entire scopes around -- I would consider this a code smell, to be honest. The view .cfm that calls view() should probably just pass in a subset of values from local that the called view cares about: #view( path = "sub/view", args = { k : local.k, l : local.l, m : local.m } )# (of course ACF may have borked that too but I'd be surprised it managed to be that screwed up!).

Thanks for at least posting back with your discoveries.