Skip to content

Commit 63dee05

Browse files
authored
Fix disposing SessionIdLoggingContext if CheckAndUpdateSessionStatus is failed (#1462)
1 parent 4e7fbc7 commit 63dee05

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/NHibernate/Impl/AbstractSessionImpl.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,17 +313,26 @@ public ProcessHelper(AbstractSessionImpl session)
313313
{
314314
_session = session;
315315
_context = new SessionIdLoggingContext(session.SessionId);
316-
session.CheckAndUpdateSessionStatus();
317-
_session._processing = true;
316+
try
317+
{
318+
_session.CheckAndUpdateSessionStatus();
319+
_session._processing = true;
320+
}
321+
catch
322+
{
323+
_context.Dispose();
324+
_context = null;
325+
throw;
326+
}
318327
}
319328

320329
public void Dispose()
321330
{
331+
_context.Dispose();
332+
_context = null;
322333
if (_session == null)
323334
throw new ObjectDisposedException("The session process helper has been disposed already");
324335
_session._processing = false;
325-
_context.Dispose();
326-
_context = null;
327336
_session = null;
328337
}
329338
}

0 commit comments

Comments
 (0)