Search code examples
cfmllucee

cfthread object empty inside of a cfthread tag in Lucee 5.2


In Lucee v5.2.9.31, the following code throws an error inside of the checkTest thread when I request the status of the test_thread thread from the cfthread object. The error I get is key [test_thread] doesn't exist.

<cfthread action="run" name="test_thread">
    <cfloop index='i' from='1' to='50'>
        <cffile action="append" file="./test_thread.txt" addNewLine="yes" output="Index: #i#" />
        <cfset sleep(500) />
    </cfloop>
</cfthread>

<cfthread action="run" name="checkTest">
    <cfset test_thread_complete = false />
    <cfloop condition="test_thread_complete eq false">
        <cfset test_thread_status = cfthread['test_thread'].status />

        <cffile action="append" file="./checkTestThread.txt" addNewLine="yes" output="#test_thread_status#" />

        <cfif test_thread_status eq 'COMPLETED'>
            <cfset test_thread_complete = true />
        </cfif>
        <cfset sleep(1000) />
    </cfloop>
</cfthread>

<cfdump var="#cfthread#" />
<cfdump var="#cfthread['test_thread']#" />

However in an older version of Lucee (v4.5.5.015), the code works as expected and generated 2 files: test_thread.txt with the incrementing index, and checkTestThread.txt which contains the status of test_thread.

In both versions, the cfdumps return the cfthread object. The first dump contains both threads and the 2nd dump contains just the test_thread object as expected.

Is this a bug in Lucee 5 or was the code exploiting a bug in earlier versions of Lucee/Railo?


Solution

  • This was caused by an update that was made to Lucee.

    According to Michael Offner (The maintainer of Lucee):

    The reason is this no longer works in Lucee, because we added support of having threads inside threads, since then "cfthread" only shows the children of the current thread, in a tree (see key "childThreads" inside "cfthread"). We cannot show all threads on one level that would create a mess, because we would show the tree of threads at the same time.

    Issue is fixed in v5.3.4.37, however the code will need to be updated as their solution adds a threadData function which returns the root cfthread object.

    In my code changing the following: <cfset test_thread_status = cfthread['test_thread'].status /> to <cfset test_thread_status = threadData()['test_thread'].status /> fixes the error and properly returns the status of a sibling thread.

    More Information: