Bug with local scope, cfthread, and ColdFusion 9

This post is more than 2 years old.

So this is a weird one. Please note that myself (and the other guys working on this) are still digging in so we may be wrong, but it appears that the use of cfthread in a CFC method, along with the use of local scope, is causing a bug in ColdFusion 9. For an example, see the code below.

<cffunction name="test"> <cfset local = structNew()>

&lt;cfthread name="doogus" action="run"&gt;

&lt;cfquery name="local.foo" datasource="ormtest"&gt;
select distinct id, name
from [user]
&lt;cfdump var="#local#"&gt;
&lt;cfreturn valueList(local.foo.id)&gt;


<cfoutput>#test()# #now()#</cfoutput><p>

As you can see, I've got a method, test, than runs a thread and then does a query. Notice I use the new local scope so I don't have to var it above. Upon running this, we are seeing an error when we try to use the valueList function. The error states that the parameter passed to valueList is invalid. Even more interesting, the dump shows only arguments.

But wait - it gets better. Both myself and Tony Nelson and others confirmed that if you run this code you will get the right result about 40% of the time. Essentially a bit less than half. On those runs, the local scope shows the query and the return runs fine.

The fix? Don't use local.whatever. If I switch to var foo = "" and then just use foo instead of local.foo, it works.

So.... any thoughts on this? I've filed bug 82861 for this.

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate for HERE Technologies. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA https://www.raymondcamden.com