Skip to content

Commit

Permalink
NH-3431 - Fix AbstractBatcher.CloseReader method which tried to use r…
Browse files Browse the repository at this point in the history
…eader after it was disposed.
  • Loading branch information
hazzik committed Feb 9, 2017
1 parent c9cf75e commit f209c2b
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/NHibernate/AdoNet/AbstractBatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ public void CloseReader(DbDataReader reader)
var actualReader = rsw == null ? reader : rsw.Target;
_readersToClose.Remove(actualReader);

var duration = GetReaderStopwatch(actualReader);

try
{
reader.Dispose();
Expand All @@ -370,17 +372,24 @@ public void CloseReader(DbDataReader reader)
}

LogCloseReader();
LogDuration(duration);
}

if (!Log.IsDebugEnabled)
return;

var nhReader = actualReader as NHybridDataReader;
actualReader = nhReader == null ? actualReader : nhReader.Target;
private Stopwatch GetReaderStopwatch(DbDataReader reader)
{
var nhReader = reader as NHybridDataReader;
var actualReader = nhReader == null ? reader : nhReader.Target;

Stopwatch duration;
if (_readersDuration.TryGetValue(actualReader, out duration) == false)
return;
_readersDuration.Remove(actualReader);
if (_readersDuration.TryGetValue(actualReader, out duration))
_readersDuration.Remove(actualReader);
return duration;
}

private static void LogDuration(Stopwatch duration)
{
if (!Log.IsDebugEnabled || duration == null) return;

Log.DebugFormat("DataReader was closed after {0} ms", duration.ElapsedMilliseconds);
}

Expand Down

0 comments on commit f209c2b

Please sign in to comment.