Skip to content

Commit c5750ee

Browse files
committed
NH-3431 - Fix AbstractBatcher.CloseReader method which tried to use reader after it was disposed.
1 parent 810b3c1 commit c5750ee

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/NHibernate/AdoNet/AbstractBatcher.cs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,11 @@ public void CloseReader(IDataReader reader)
358358
var actualReader = rsw == null ? reader : rsw.Target;
359359
_readersToClose.Remove(actualReader);
360360

361+
var duration = GetReaderStopwatch(actualReader);
362+
361363
try
362364
{
365+
//TODO: Shouldn't we close reader instead?
363366
reader.Dispose();
364367
}
365368
catch (Exception e)
@@ -369,17 +372,24 @@ public void CloseReader(IDataReader reader)
369372
}
370373

371374
LogCloseReader();
375+
LogDuration(duration);
376+
}
372377

373-
if (!Log.IsDebugEnabled)
374-
return;
375-
376-
var nhReader = actualReader as NHybridDataReader;
377-
actualReader = nhReader == null ? actualReader : nhReader.Target;
378+
private Stopwatch GetReaderStopwatch(DbDataReader reader)
379+
{
380+
var nhReader = reader as NHybridDataReader;
381+
var actualReader = nhReader == null ? reader : nhReader.Target;
378382

379383
Stopwatch duration;
380-
if (_readersDuration.TryGetValue(actualReader, out duration) == false)
381-
return;
382-
_readersDuration.Remove(actualReader);
384+
if (_readersDuration.TryGetValue(actualReader, out duration))
385+
_readersDuration.Remove(actualReader);
386+
return duration;
387+
}
388+
389+
private static void LogDuration(Stopwatch duration)
390+
{
391+
if (!Log.IsDebugEnabled || duration == null) return;
392+
383393
Log.DebugFormat("DataReader was closed after {0} ms", duration.ElapsedMilliseconds);
384394
}
385395

0 commit comments

Comments
 (0)