Skip to content

Commit ed71e55

Browse files
committed
CSHARP-1515: Dispose of cursor in AsyncCursorEnumeratorAdapter.
1 parent 33151e0 commit ed71e55

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/MongoDB.Driver/Sync/AsyncCursorEnumeratorAdapter.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,21 @@ public IEnumerator<TDocument> GetEnumerator()
4242
throw new ObjectDisposedException(GetType().FullName);
4343
}
4444

45-
while (_cursor.MoveNext(_cancellationToken))
45+
try
4646
{
47-
var batch = _cursor.Current;
48-
foreach (var document in batch)
47+
while (_cursor.MoveNext(_cancellationToken))
4948
{
50-
yield return document;
49+
var batch = _cursor.Current;
50+
foreach (var document in batch)
51+
{
52+
yield return document;
53+
}
5154
}
5255
}
56+
finally
57+
{
58+
Dispose();
59+
}
5360
}
5461

5562
public void Dispose()

0 commit comments

Comments
 (0)