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

PowerShell menu completion parser thread-safety fix #17221

Merged
merged 1 commit into from
May 9, 2024
Merged

PowerShell menu completion parser thread-safety fix #17221

merged 1 commit into from
May 9, 2024

Conversation

krzysdz
Copy link
Contributor

@krzysdz krzysdz commented May 8, 2024

Fix Terminal crashing when experimental PowerShell menu completion is very quickly invoked multiple times.

Command::ParsePowerShellMenuComplete can be called from multiple threads, but it uses a static Json::CharReader, which cannot safely parse data from multiple threads at the same time. Removing static fixes the problem, since every function call gets its own reader.

Validation: Pressed Ctrl+Space quickly a few times with hardcoded huge JSON as the completion payload. Also shown at the end of the second video in #17220.

Closes #17220

`Command::ParsePowerShellMenuComplete` can be called from multiple threads, but it uses a `static` `Json::CharReader`, which cannot safely parse data from multiple threads at the same time.
Without `static` every function call will use a separate `CharReader`.
Copy link
Member

@zadjii-msft zadjii-msft left a comment

Choose a reason for hiding this comment

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

well you know, in retrospect, this is obvious 😓 thanks for fixing my bugs

@lhecker lhecker added this pull request to the merge queue May 9, 2024
@DHowett DHowett removed this pull request from the merge queue due to a manual request May 9, 2024
@DHowett DHowett added this pull request to the merge queue May 9, 2024
@@ -690,7 +690,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
auto data = winrt::to_string(json);

std::string errs;
static std::unique_ptr<Json::CharReader> reader{ Json::CharReaderBuilder{}.newCharReader() };
std::unique_ptr<Json::CharReader> reader{ Json::CharReaderBuilder{}.newCharReader() };
Copy link
Member

Choose a reason for hiding this comment

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

that's subtle. thanks!

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks May 9, 2024
@DHowett DHowett added this pull request to the merge queue May 9, 2024
Merged via the queue into microsoft:main with commit 44516ad May 9, 2024
15 checks passed
DHowett pushed a commit that referenced this pull request May 13, 2024
Fix Terminal crashing when experimental PowerShell menu completion is
very quickly invoked multiple times.

`Command::ParsePowerShellMenuComplete` can be called from multiple
threads, but it uses a `static` `Json::CharReader`, which cannot safely
parse data from multiple threads at the same time. Removing `static`
fixes the problem, since every function call gets its own `reader`.

Validation: Pressed Ctrl+Space quickly a few times with hardcoded huge
JSON as the completion payload. Also shown at the end of the second
video in #17220.

Closes #17220

(cherry picked from commit 44516ad)
Service-Card-Id: 92524217
Service-Version: 1.21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

Quickly invoking PowerShell menu completion multiple times crashes Terminal
4 participants