Fix search indexer "Source array was not long enough" error in Command Palette#21
Draft
Fix search indexer "Source array was not long enough" error in Command Palette#21
Conversation
…e InPlaceUpdateList Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] search indexer
Fix search indexer "Source array was not long enough" error in Command Palette
Jun 26, 2025
Owner
|
how to reproduce the issue? |
Author
To reproduce the "Source array was not long enough" error in Command Palette: Prerequisites:
Reproduction Steps:
Root Cause:
The race condition is timing-dependent, so it may require several attempts with rapid typing to trigger consistently. |
Owner
|
hot to update the code to make it more easy to reproduce? |
Author
To make the race condition easier to reproduce, I'll modify the code to:
This will make the "Source array was not long enough" error much more likely to occur during testing. |
…tress testing Co-authored-by: lei9444 <39758135+lei9444@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes a race condition in the Command Palette's search indexer that was causing "Source array was not long enough" exceptions when using the "Search files" extension.
Root Cause
The error occurred in
ListViewModel.FetchItems()when LINQ expressions likeItems.Where(i => !i.IsInErrorState)were passed directly toListHelpers.InPlaceUpdateList(). If the underlyingItemscollection was modified concurrently during enumeration, it would cause the enumerable to fail when materialized, resulting in:Changes Made
1. ListViewModel.cs
Items.Where(i => !i.IsInErrorState)to a list before passing toInPlaceUpdateListFilterList(Items, Filter)result before passing toInPlaceUpdateList2. ListHelpers.cs
newContentsparameter inInPlaceUpdateListto prevent concurrent modification issuesnewListinstead of the originalnewContentsenumerableBefore & After
Before:
After:
Testing
Created comprehensive tests that simulate the race condition scenario:
Impact
Fixes #20.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.