NHibernate issue a log.Warn() about unclosed connection when Disposing a connection

Description

using (ISession session = Factory.OpenSession())
{
//Do Work
}

The above code will cause a warning to be issues from NHibernate about an unclosed connection, this is contrary to expectation, as the code clean up after itself properly

Environment

WinXp

Activity

MikeM 
February 25, 2005 at 4:27 PM

0.7 was released

MikeM 
February 23, 2005 at 5:13 AM

Hi Ayende, the code causing this problem was modified quite a bit and no longer does this. ISession implements IDisposable in a more .net standard way now.

OrenE 
February 22, 2005 at 11:14 PM

The issue that I've with this is that the debug level is too high and the message is misleading.
The comment: Just in case the user forgot to Commit() or Close() seems to say that Dispose will be called by the system, but there are many instances where the user will call it.

IMHo, the debug level should go to debug and the message should say things like: "Disposing session with closed connection", "Disposing session with opened connection", and a finalizer should be added, Then you can supress finalization in the Dispose, and if the finalizer is called, log it as Error (unclosed/undisposed) session and release the resources.

OrenE 
February 22, 2005 at 11:10 PM

I'm using NHibernate 0.6, you can find the relevant code in SessionImpl.cs line 3929.

/// <summary>
/// Just in case the user forgot to Commit() or Close()
/// </summary>
void IDisposable.Dispose()
{
log.Debug( "running ISession.Dispose()" );

// it was never disconnected
if( connection != null )
{
AfterTransactionCompletion();

if( connection.State == ConnectionState.Closed )
{
log.Warn( "finalizing unclosed session with closed connection" );
}
else
{
log.Warn( "unclosed connection" );
if( autoClose )
{
connection.Close();
}
}
}
}

MikeM 
February 22, 2005 at 6:50 PM

Hi Ayende, are you using the code from cvs or a prebuilt NHibernate.dll? There's been quite a bit of work in cvs around IDisposable and I can't find the scenario you're describing in the source code.

Mike

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created February 22, 2005 at 4:25 PM
Updated February 25, 2005 at 4:27 PM
Resolved February 23, 2005 at 5:13 AM
Who's Looking?