Skip to content

Commit 452b43b

Browse files
committed
NH-3431: Fix AbstractBatcher.CloseReader method which tried to use reader after it was disposed.
1 parent 2eea3b4 commit 452b43b

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
@@ -359,8 +359,11 @@ public void CloseReader(DbDataReader reader)
359359
var actualReader = rsw == null ? reader : rsw.Target;
360360
_readersToClose.Remove(actualReader);
361361

362+
var duration = GetReaderStopwatch(actualReader);
363+
362364
try
363365
{
366+
//TODO: Shouldn't we close reader instead?
364367
reader.Dispose();
365368
}
366369
catch (Exception e)
@@ -370,17 +373,24 @@ public void CloseReader(DbDataReader reader)
370373
}
371374

372375
LogCloseReader();
376+
LogDuration(duration);
377+
}
373378

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

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

0 commit comments

Comments
 (0)