Application Scope Leak & Zombie DB connections when ORM inside CFTHREAD

Description

If you perform ORM actions inside of a cfthread/thread, it appears that it leaks datasource info from another application scope which results in an error when you try to perform any other orm action (i.e. entityLoad) outside of the thread. This will result in an error:
Session for the datasource [mydatasource]

The error object's ExtraInfo will list the available datasources and loaded entities, which in our case was from a different application running on the same server (same code base, different application name). This was consistently repeatable by running several simultaneous requests to each site (we used load testing tool to simulate 5 users accessing random sites on the server at the same time for 10 seconds).

This also manifests in keeping idle database connections open, which in our case eventually used up all available database connections causing connection failures in production.

The work around for us was to add ormCloseSession(); at the end of the cfthread block:

thread action="run" name=createUUID() { //do orm stuff here ormCloseSession(); }

This resolves both issues, but is very much a hack.

 

UPDATE

I’ve attached a scaled down repro. Just unzip somewhere and follow the instructions in the README.md to see the bug in action.

Environment

None

Attachments

1
  • 01 Apr 2021, 12:18 am

Activity

Show:

Abram Adams 13 April 2021 at 22:43

That seems to have fixed our issue! Thanks for the quick turnaround. I’ll leave my work around in place until this is released, but kudos for being so responsive 🙂

Pothys - MitrahSoft 13 April 2021 at 15:31

This issue was solved in lucee version 5.3.8.164-SNAPSHOT. Could you please check with this version and report here back?

Zac Spitzer 1 April 2021 at 21:42

Pothys - MitrahSoft 1 April 2021 at 11:28
Edited

I've checked this ticket and confirmed the issue happened on lucee latest version 5.3.8.163-SNAPSHOT also. Using ORM inside the thread and try to perform another ORM action outside the thread in a CFML code. simultaneous requests to the same code from a different site with a different application throws an error like there is no Session for the datasource [ test4-LDEV-3411 ]. The mentioned workaround uses ORMcloseSession() with datasource setting exclusive connection for request enabled works fine. Seems ACF works in this scenario. Request from the same site means works in lucee too.

FYI, I use command box and below the code instead of using k6 testing tool.

<cfscript> for( i = 0; i <= 10; i++){ ranNum = randRange(1,4); if(ranNum == 1) ranNum = ""; cfhttp( method="get",url="http://test#ranNum#.ldev-3411.test:52717/withoutcloseSession.cfm"); writeDump(var=cfhttp.statuscode); } </cfscript>

Here is the Stack trace

"ERROR","cfthread-6","04/01/2021","15:58:13","cfthread-6","there is no Session for the datasource [test4-LDEV-3411];there is no Session for the datasource [test4-LDEV-3411];lucee.runtime.exp.ApplicationException: there is no Session for the datasource [test4-LDEV-3411] at lucee.runtime.op.ExceptonImpl.createApplicationException(ExceptonImpl.java:93) at lucee.runtime.orm.ORMExceptionUtil.createException(ORMExceptionUtil.java:45) at lucee.runtime.util.ORMUtilImpl.createException(ORMUtilImpl.java:109) at org.lucee.extension.orm.hibernate.ExceptionUtil.createException(ExceptionUtil.java:34) at org.lucee.extension.orm.hibernate.ExceptionUtil.createException(ExceptionUtil.java:18) at org.lucee.extension.orm.hibernate.HibernateORMSession.getSession(HibernateORMSession.java:77) at org.lucee.extension.orm.hibernate.HibernateORMSession.save(HibernateORMSession.java:252) at lucee.runtime.functions.orm.EntitySave.call(EntitySave.java:34) at lucee.runtime.functions.orm.EntitySave.call(EntitySave.java:29) at withoutclosesession_cfm$cf.threadCall(/withoutCloseSession.cfm:8) at lucee.runtime.thread.ChildThreadImpl.execute(ChildThreadImpl.java:203) at lucee.runtime.thread.ChildThreadImpl.run(ChildThreadImpl.java:145))
Done

Details

Assignee

Reporter

Priority

Fix versions

New Issue warning screen

Before you create a new Issue, please post to the mailing list first https://dev.lucee.org

Once the issue has been verified, one of the Lucee team will ask you to file an issue

Affects versions

Created 31 March 2021 at 18:25
Updated 13 April 2021 at 22:52
Resolved 13 April 2021 at 22:52

Flag notifications