Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Union doesn't dispose enumerator for empty lists #2112

Closed
Bouke opened this issue May 14, 2024 · 1 comment · Fixed by #2131
Closed

Union doesn't dispose enumerator for empty lists #2112

Bouke opened this issue May 14, 2024 · 1 comment · Fixed by #2131

Comments

@Bouke
Copy link

Bouke commented May 14, 2024

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)

@idg10
Copy link
Collaborator

idg10 commented Jun 18, 2024

Thanks. I added a few tests to confirm the problem, and then verified that the fix you suggest does seem to fix it.

There are a fair few items on the backlog for Async LINQ. I'm hoping to get through a few more of them before doing another release, but if this is blocking you, let me know, and I can do a release without waiting to get any other fixes in.

idg10 added a commit that referenced this issue Jun 19, 2024
* Fix Union Dispose bug #2112
* Update Ix build to use .NET 8.0 SDK
* Align ref project names with assembly names (This seems to have become necessary in .NET SDK 8.0.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants