Fix potential ArgumentOutOfRangeException
in LeaseBasedQueueBalancer
#9112
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's a potential for an
ArgumentOutOfRangeException
in theLeaseBasedQueueBalancer
. This can happen when we remove an element from_myQueues
while iterating over the results array. When we callRemoveAt(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 wherei
is equal to or greater than the new length of_myQueues
, attempting to access_myQueues[i]
will throw anArgumentOutOfRangeException
. 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