JoshClose / CsvHelper

Library to help reading and writing CSV files
http://joshclose.github.io/CsvHelper/
Other
4.63k stars 1.05k forks source link

CsvWriter.WriteRecordsAsync does not dispose e.g. EF Core AsyncEnumerators #2264

Open CaringDev opened 4 weeks ago

CaringDev commented 4 weeks ago

The CsvWriter.WriteRecordsAsync overload for IAsyncEnumerable<T> creates an IAsyncEnumerator but does not dispose implementations not implementing IDisposable. When using EF Core with streaming results this leads to concurrent queries on the same DbContext. As this is not allowed e.g. for Postgres a Npgsql.NpgsqlOperationInProgressException is thrown on subsequent operations. As IAsyncEnumerator implements IAsyncDisposable we should unconditionally await DisposeAsync.