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

Prevent System.ArgumentException #133

Closed
wants to merge 1 commit into from

Conversation

Optano-Dev
Copy link

Prevent System.ArgumentException: 'The tasks argument included a null value. (Parameter 'tasks')'.

Where Iterator uses the original source array to iterate. So it is crucial to not call .ToList() or create a new array.

This solves #128

@@ -62,7 +63,7 @@ public override async Task OnActivateAsync()
subscriptionTasks[i] = subscription.ResumeAsync((serverId, _) => OnDisconnect("server-disconnected"));
}

await Task.WhenAll(subscriptionTasks);
await Task.WhenAll(subscriptionTasks.Where(task => task != null));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be a slice instead: ArrayPool.Rent returns an array which is at least the requested length, so the non-null items will always be at the beginning and the null items will always be at the end.

However, given that we need to trim the array and Task.WhenAll will convert whatever you pass it into an array (or is it a list?), it would be cheaper just to declare subscriptionTasks as a new List with no pooling.

@galvesribeiro
Copy link
Member

Thanks for the PR. It was fixed later. It ended up like this:

var subscriptions = await _serverDisconnectedStream.GetAllSubscriptionHandles();
            var subscriptionTasks = new Task[subscriptions.Count];
            for (int i = 0; i < subscriptions.Count; i++)
            {
                var subscription = subscriptions[i];
                subscriptionTasks[i] = subscription.ResumeAsync((serverId, _) => OnDisconnect("server-disconnected"));
            }

            await Task.WhenAll(subscriptionTasks);

I'm closing this PR. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants