Wrap reading+writing workspace state operations with mutexes. #646
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 of Changes
The methods in
ResourceManager
which partially mutate their key values using a pattern like:could potentially race with concurrent callers, and while the first caller was performing either steps 1 or 3, a concurrent caller number two could be scheduled which completes 3, meanwhile the first caller operated on stale data and its step 3. will revert what the second caller wrote.
Fix using async mutexts (one per each workspace storage key) guarding across steps 1..3 above, serializing the concurrent callers. New utility method
runWithMutex(key, callback)
will run the given callback (the original body of the method performing 1..3) while holding the mutex corresponding to the workspace storage key being partially mutated.While it is unclear if a user could be fast enough to cause such a race condition, best to do things in a more concurrent-safe manner.
Any additional details or context that should be provided?
ResourceManager
identified one in-development issue (a missing await) during implementation, yay.Pull request checklist
Please check if your PR fulfills the following (if applicable):
Tests
Other
.vsix
file?