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

Wrap reading+writing workspace state operations with mutexes. #646

Merged

Conversation

jlrobins
Copy link
Contributor

@jlrobins jlrobins commented Nov 19, 2024

Summary of Changes

  • The methods in ResourceManager which partially mutate their key values using a pattern like:

    1. Async read the existing key value as either an array or a map.
    2. Mutate that array or map.
    3. Async write the mutated array or map back to workspace storage.

    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?

Pull request checklist

Please check if your PR fulfills the following (if applicable):

Tests
  • Added new
  • Updated existing
  • Deleted existing
Other
  • All new disposables (event listeners, views, channels, etc.) collected as for eventual cleanup?
  • Does anything in this PR need to be mentioned in the user-facing CHANGELOG or README?
  • Have you validated this change locally by packaging and installing the extension .vsix file?
    gulp clicktest

@jlrobins jlrobins requested a review from a team as a code owner November 19, 2024 20:35
@confluent-cla-assistant
Copy link

🎉 All Contributor License Agreements have been signed. Ready to merge.
Please push an empty commit if you would like to re-run the checks to verify CLA status for all contributors.

@jlrobins jlrobins changed the title Wrap reading+writing workspace state operations with a mutex. Wrap reading+writing workspace state operations with mutexes. Nov 20, 2024
Copy link
Contributor

@shouples shouples left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💪

@jlrobins jlrobins merged commit 820395a into main Nov 20, 2024
2 checks passed
@jlrobins jlrobins deleted the 534-guard-resource-manager-sub-family-methods-with-async-mutexes branch November 20, 2024 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Guard resource manager sub-family methods with async-mutexes
2 participants