Sometimes CFTHREAD cannot join with other CFTHREAD of same page. Pls open ticket if you can/want

Hi,

I’m testing cfthread since few days now in order to develop a specifc
backend feature.
I know about ACF9 behaviour and that’s why this led me to this recently
: Redirecting to Google Groups

Today I’ve encounter a kind of problem/bug with Lucee’s cfthread (Lucee
4.5.1.015 / JDK7, Tomcat8 / Linux).
I would describe the bug as follow :

  • Sometimes onRequestEnd() is finished before all child threads are
    created/started.
  • Maybe this happens randomly but when it is the case then a given child
    thread will fail to join with others.
  • i.e The child thread
    getPageContext().getParentPageContext().getThreadScopeNames() will
    return an empty array.

One possible explanation could be that thread creation/start is deferred
from the application listener execution.
One workaround in the meantime is to make the current request wait for all
thread creation/start before onRequestEnd().

If someone could confirm this issue and/or raise a ticket I would really
appreciate (In fact I could but long and hard to explain why I don’t).
Also you may not be able to easily reproduce the bug (may or may not)
because this may seem to happen randomly while it doesn’t.
In my case I couldn’t reproduce the bug when I refreshed the same page. But
I could when I open the same page in a new browser page (i.e instead of
refreshing).

This is a snippet which could help to understand the issue (the “var”
keywords came from a function of mine…) :

// Say this file is index.cfm and an Application.cfc exists in the same dir
// A basic thread
cfthread(name="T1",action="run") {
	writeLog("=== T1 starts ===");
	// Does a lot of thing here which last more than a second
};
// Another thread which wants to join with the first above
cfthread(name="T1-monitor",action="run") {
	writeLog("=== T1 monitor starts ===");
	try {
		threadJoin("T1",someTimeouValue);
		// Does a lot of thing here which last more than a second
	} catch(any error) {
		// An exception is catched here when the bug occurs
		// It mainly says that there's no thread named "T1" and that there's no other threads eithers in the page context
	}
};
/* Say in Application.onRequestStart() there's a log like "Executing onRequestStart()"
And in Application.onRequestEnd() there's a log like "Executing onRequestEnd()".

So when the bug occurs, then you get the following log output :
-> "Executing onRequestStart()"
-> "Executing onRequestEnd()"
-> "=== T1 starts ==="
-> "=== T1 monitor starts ==="

And when the bug DOES NOT occurs, then you get the following log output :
-> "Executing onRequestStart()"
-> "=== T1 starts ==="
-> "=== T1 monitor starts ==="
-> "Executing onRequestEnd()"
*/</cfscript>

One can test the result of one of : structKeyList(cfthread),
getPageContext().getThreadScopeNames(), etc…

PS : Also if someone could advice a good online copy/paste cfml syntax
highlighter that works with google groups…

Hence the workaround I stated cannot work (sadly) i.e “making the current
request thread wait for child thread creation before onRequestEnd()” → No
effectOn Tuesday, June 2, 2015 at 5:09:43 PM UTC+2, Desmond Miles wrote:

I’ve noticed that my log example in the comment above may be confusing to
understand the real issue here…
So please notice that this bug “probably” occurs because the main page
context content is released before the doJoin() could get the thread names
from the parent page context.

I’ve noticed that my log example in the comment above may be confusing to
understand the real issue here…
So please notice that this bug “probably” occurs because the main page
context content is released before the doJoin() could get the thread names
from the parent page context.

For those interested, the current error message can be foun here in
doJoin() :
Bitbucket
https://bitbucket.org/lucee/lucee/src/2a207d2b9da27d9935afc48d069627cb1bb47069/lucee-java/lucee-core/src/lucee/runtime/tag/ThreadTag.java?at=master#cl-334

PS : Sorry for posting several pieces like that :frowning:

My first ticket created ! Here
: [LDEV-380] - Lucee




<!— Sleep long enough —>
<cfset sleep(waitBeforeJoin + waitToMakeJoinHappenBefore + 2000)>



<!— This sleep will cause the bug if it last too long than waitToMakeJoinHappenBefore Because Application.onRequestEnd() will finish before this join i.e getThreadScopeName() is empty For example these values won’t never cause the error → waitBeforeJoin=500 → waitToMakeJoinHappenBefore=waitBeforeJoin + 700 —>
<cfif waitBeforeJoin GT 0>
<cfset sleep(waitBeforeJoin)>

<!— Join sometimes fails because getPageContext().getParentContext().getThreadScopeName() is empty Error : “T2 join error: there is no thread running with the name [t1], only the following threads existing []” —>





<!— Sometimes this can be a workaround : Wait and perhaps the join will start before onRequestEnd() —><cfif waitToMakeJoinHappenBefore GT 0>
<cfset sleep(waitToMakeJoinHappenBefore)>

Page ends i.e next is Application.onRequestEnd()