tracker issue : CF-4206046

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

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: 2016,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 {
			udf();
		} 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.

java.util.ConcurrentModificationException
        at java.base/java.util.HashMap$HashIterator.nextNode(Unknown Source)
        at java.base/java.util.HashMap$EntryIterator.next(Unknown Source)
        at java.base/java.util.HashMap$EntryIterator.next(Unknown Source)
        at coldfusion.runtime.LocalScope.isEmpty(LocalScope.java:274)
        at coldfusion.runtime.NeoPageContext.searchScopes(NeoPageContext.java:887)
        at coldfusion.runtime.NeoPageContext.findAttribute(NeoPageContext.java:701)
        at coldfusion.runtime.CfJspPage._get(CfJspPage.java:354)
        at coldfusion.runtime.CfJspPage._get(CfJspPage.java:339)
        at coldfusion.runtime.CfJspPage._get(CfJspPage.java:326)
        at coldfusion.runtime.CfJspPage._get(CfJspPage.java:302)
        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.

Attachments:

Comments:

Related ticket for Closure instances: https://tracker.adobe.com/#/view/CF-4206045 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