Better fix for file browser race condition #23879
Merged
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.
With further testing I found I was still occasionally hitting the error in #23832
Dug into it more and found out that while the order the messages was being sent in was now correct, the STS code still has async issues.
Here is the handler for the open request : https://github.com/microsoft/sqltoolsservice/blob/main/src/Microsoft.SqlTools.ServiceLayer/FileBrowser/FileBrowserService.cs#L96
Notice that we kick off the task but then immediately return true - which then allows the follow message to start processing. Normally the order would be expected to be this :
But because we weren't awaiting the first one to finish this is what happened
The STS code isn't great, but in this case I found an even better solution was to remove the unnecessary second open message (with changeFilter) from even happening. This means that on launch of the dialog we only ever send the initialize message anyways and so there's no chance of any error happening. Passing in the item to select directly into setOptions skips the logic to send the "selection changed" event and so we never send that second message. This not only fixes the issue, but also improves performance since we don't have to redraw the tree for the second message.