Skip to content

Commit 4139e26

Browse files
committed
DataReader correcly handles disposal of preloaded tuple collection
1 parent e02956a commit 4139e26

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

Orm/Xtensive.Orm/Orm/Providers/CommandProcessing/DataReader.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,16 @@ public async ValueTask DisposeAsync()
9595
await command.DisposeAsync().ConfigureAwait(false);
9696
}
9797
else {
98-
await ((IAsyncEnumerator<Tuple>) source).DisposeAsync().ConfigureAwait(false);
98+
if (source is IAsyncEnumerator<Tuple> asyncSource) {
99+
// true async enumerable source
100+
await asyncSource.DisposeAsync().ConfigureAwait(false);
101+
}
102+
else {
103+
// preloaded collection of elements,
104+
// like in case of delayed query which has already been read from database
105+
// or greedy enumeration
106+
((IEnumerator<Tuple>) source).Dispose();
107+
}
99108
}
100109
}
101110

0 commit comments

Comments
 (0)