tracker issue : CF-4206046

select a category, or use search below
(searches all categories and all time range)

UDF instances are not thread safe to execute in separate threads

| View in Tracker

Status/Resolution/Reason: To Fix//BugVerified

Reporter/Name(from Bugbase): Bradley W. / ()

Created: 11/21/2019

Components: Language

Versions: 2018

Failure Type: Data Corruption

Found In Build/Fixed In Build: Update 5 /

Priority/Frequency: Normal / Unknown

Locale/System: English / Platforms All

Vote Count: 10

Problem Description:

If a UDF is declared once and then shared by two threads that run it at the same time, it is not thread safe.  The UDF keeps a reference to the page context where it was declared and the LocalScope.isEmpty() method is not thread safe.

Steps to Reproduce:

Tail your ColdFusion-out log while running this code

function udf() {}

cfloop( from="1", to="10000", index="i" ) {  
	thread name='test#i#' {
		try {
		} catch( any e ) {
			writeDump( var=e.stacktrace, output="console" );

Actual Result:

After several runs, you'll see one or more threads throw this error, which will show in the console output.

        at java.base/java.util.HashMap$HashIterator.nextNode(Unknown Source)
        at java.base/java.util.HashMap$ Source)
        at java.base/java.util.HashMap$ Source)
        at coldfusion.runtime.LocalScope.isEmpty(
        at coldfusion.runtime.NeoPageContext.searchScopes(
        at coldfusion.runtime.NeoPageContext.findAttribute(
        at coldfusion.runtime.CfJspPage._get(
        at coldfusion.runtime.CfJspPage._get(
        at coldfusion.runtime.CfJspPage._get(
        at coldfusion.runtime.CfJspPage._get(
        at cfindex2ecfm1403424347$func_CFFUNCCFTHREAD_CFINDEX2ECFM14034243471.runFunction(C:\sandbox\adobeThreading\index.cfm:8)

Expected Result:

10,000 threads should run the UDF with no errors.

Any Workarounds:

Single thread the execution of the UDF, which of course, makes the threading moot.



Related ticket for Closure instances: This ticket is a blocker for the cbstreams library which shares Closures across threads but this bug could bite any CF codebase sharing a Closure.
Comment by Bradley W.
31825 | November 21, 2019 03:07:34 PM GMT
Great catch, Bradley! In general, independent requests to a user-defined function should not affect each other.
Vote by A. B.
31826 | November 22, 2019 01:51:59 PM GMT