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

Fix potential ArgumentOutOfRangeException in LeaseBasedQueueBalancer #9112

Merged
merged 1 commit into from
Aug 13, 2024

Conversation

ledjon-behluli
Copy link
Contributor

@ledjon-behluli ledjon-behluli commented Aug 13, 2024

There's a potential for an ArgumentOutOfRangeException in the LeaseBasedQueueBalancer. This can happen when we remove an element from _myQueues while iterating over the results array. When we call RemoveAt(i), we are reducing the size of _myQueues, on subsequent iterations of the for loop, i will increase, but the length of _myQueues has decreased. If we reach a point where i is equal to or greater than the new length of _myQueues, attempting to access _myQueues[i] will throw an ArgumentOutOfRangeException. This fix simply loops backwards, this way removing items from _myQueues will not affect the indices of the remaining elements that are yet to be processed.

Microsoft Reviewers: Open in CodeFlow

@ReubenBond ReubenBond merged commit 21e8f94 into dotnet:main Aug 13, 2024
22 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants