Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/CsvHelper.Website/input/change-log/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

### 33.0.2

#### Bug Fixes

- Dispose of IAsyncDisposable enumerators in CsvWriter

### 33.0.1

#### Bug Fixes
Expand Down
25 changes: 19 additions & 6 deletions src/CsvHelper/CsvWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,9 +506,13 @@ public virtual async Task WriteRecordsAsync(IEnumerable records, CancellationTok
}
finally
{
if (enumerator is IDisposable en)
if (enumerator is IAsyncDisposable asyncDisposable)
{
en.Dispose();
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
}
else if (enumerator is IDisposable disposable)
{
disposable.Dispose();
}
}
}
Expand Down Expand Up @@ -566,10 +570,15 @@ public virtual async Task WriteRecordsAsync<T>(IEnumerable<T> records, Cancellat
}
finally
{
if (enumerator is IDisposable en)
if (enumerator is IAsyncDisposable asyncDisposable)
{
en.Dispose();
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
}
else if (enumerator is IDisposable disposable)
{
disposable.Dispose();
}

}
}

Expand Down Expand Up @@ -626,9 +635,13 @@ public virtual async Task WriteRecordsAsync<T>(IAsyncEnumerable<T> records, Canc
}
finally
{
if (enumerator is IDisposable en)
if (enumerator is IAsyncDisposable asyncDisposable)
{
en.Dispose();
await asyncDisposable.DisposeAsync().ConfigureAwait(false);
}
else if (enumerator is IDisposable disposable)
{
disposable.Dispose();
}
}
}
Expand Down