Memory leak when using ORM code in threads

Description

Any ORM session opened in a thread is left opened along with all attached ORM objects. This is the textbook definition of a memory leak, and will eventually result in an OutOfMemory exception if we use threads to do any processing of large ORM entities.

The number of “orphaned” sessions grows with each page request and never decreases. i.e., Lucee never closes these sessions, whether after the request ends or otherwise. Even an ApplicationStop() or ormReload() fails to close the open sessions.

Once outside the thread, there is no way to reference or close these ORM sessions.

Environment

I have tested this on: Lucee 5.3.10.97 with the latest Hibernate extension versions:

  • Hibernate 5.4.29.20-BETA

  • Hibernate 3.5.5.87

Attachments

2

relates to

Activity

Show:

Michael Born @ Ortus 7 June 2023 at 03:04

It looks like that documentation for the ORM settings hasn’t changed in 8 years. autoManageSession has been supported in Lucee for a long time, you can see with a quick code search:

Here’s where the Hibernate extension flushes the session upon transaction begin:

and clears the session upon transaction rollback:

Here’s where the ORMReload tag flushes and closes all sessions (minus sessions opened in a cfthread, as discussed in the ticket):

All of these only happen if autoManageSession is enabled, so yeah it’s supported.

Zac Spitzer 6 June 2023 at 13:53

(disabled)

Zac Spitzer 6 June 2023 at 08:52

test case

Michael Born @ Ortus 5 June 2023 at 17:05

why did you close this ticket? I hope it’s not Rejected, and I know it’s certainly not Fixed. The issue you linked to as well, , doesn’t contain any of the details or repro case like this one does. Finally, closing the ORM sessions on application stop is definitely a good step, but it does not resolve this memory leak. You can’t ask users to cycle the CFML application just to close leaky session objects!

Fixed

Details

Assignee

Reporter

Priority

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

Sprint

Affects versions

Created 21 December 2022 at 14:47
Updated 6 March 2025 at 11:41
Resolved 4 June 2023 at 10:52