Add debugging option for detecting if a Session is unclosed

Description

In H2 the Session would log a warning if close was not called. This was removed in H3 due to performance issues of using a finalizer.

It can often be very difficult to track down unclosed Sessions so I would like to propose an option be added for restoring this functionality with an enhancement.

Add a Session implementation that wraps another Session which will

  • Pass through all methods.

  • Create but not throw an Exception on creation

  • Watch for "closure" methods and record as appropriate.

  • Have a finalizer that checks for the Session not being closed and logs a warning and the exception created with the Session's stacktrace.

Then on any Session creation by SessionFactory, if the option is enabled, wrap the Session with the wrapper above.

This will have performance implications because of the finalizer and the Exception creation per Session. But as a debugging tool it could be very useful.

I am open to creating a patch if there is interest.

Activity

Christian BeikovApril 4, 2024 at 1:00 PM

Since finalizers are deprecated as of Java 9, you will have to do that by registering created sessions in a java.lang.ref.Cleaner yourself.

MikeMJuly 3, 2007 at 6:29 PM

Instead of

'This will have performance implications because of the finalizer and the Exception creation per Session'

I should have said

'This will have performance implications because of the finalizer and the Exception creation per Session BUT will work and perform as usual when the option is disabled'

Rejected

Details

Assignee

Reporter

Components

Priority

Created July 3, 2007 at 6:28 PM
Updated April 4, 2024 at 1:00 PM
Resolved April 4, 2024 at 1:00 PM