Skip to content

Union doesn't dispose enumerator for empty lists #2112

@Bouke

Description

@Bouke

UnionAsyncIterator has the same issue as reported for UnionIterator and fixed in .NET 5. It seems as simple as moving the call to SetEnumeratorAsync up just before the if.

++_index;
var enumerator = enumerable.GetAsyncEnumerator(_cancellationToken);
if (await enumerator.MoveNextAsync().ConfigureAwait(false))
{
await SetEnumeratorAsync(enumerator).ConfigureAwait(false);
StoreFirst();

vs

        IEnumerator<TSource> enumerator = enumerable.GetEnumerator();
        SetEnumerator(enumerator);
        
        ++_state;
        if (enumerator.MoveNext())
        {
            StoreFirst();

(source: https://github.com/dotnet/runtime/blob/714a4420805ed53c311b05381c83c88894100fa9/src/libraries/System.Linq/src/System/Linq/Union.cs#L172-L178)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions