From 44516ad7cffef1996cabc5bf7435937ee32ba51d Mon Sep 17 00:00:00 2001 From: krzysdz Date: Thu, 9 May 2024 18:29:47 +0000 Subject: [PATCH] PowerShell menu completion parser thread-safety fix (#17221) 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 --- src/cascadia/TerminalSettingsModel/Command.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/Command.cpp b/src/cascadia/TerminalSettingsModel/Command.cpp index a32ed4efa79..70f63091a1f 100644 --- a/src/cascadia/TerminalSettingsModel/Command.cpp +++ b/src/cascadia/TerminalSettingsModel/Command.cpp @@ -690,7 +690,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation auto data = winrt::to_string(json); std::string errs; - static std::unique_ptr reader{ Json::CharReaderBuilder{}.newCharReader() }; + std::unique_ptr reader{ Json::CharReaderBuilder{}.newCharReader() }; Json::Value root; if (!reader->parse(data.data(), data.data() + data.size(), &root, &errs)) {