Additional instances of WT crash on exit #19938

Closed
opened 2026-01-31 06:58:02 +00:00 by claunia · 10 comments
Owner

Originally created by @alabuzhev on GitHub (May 23, 2023).

Windows Terminal version

1.18.1421.0

Windows build number

10.0.19045.2728

Other Software

N/A

Steps to reproduce

This is probably related to

All instances of Windows Terminal now run in the same process (https://github.com/microsoft/terminal/pull/14843)

  1. Run WT.
  2. Run WT again.

Expected Behavior

Two WT windows

Actual Behavior

Two WT windows and an extra error dialog:

image

image

Stack trace:

>	twinapi.appcore.dll!Microsoft::WRL::ActivationFactory<struct Microsoft::WRL::Implements<struct Microsoft::WRL::RuntimeClassFlags<3>,struct Windows::ApplicationModel::Core::ICoreApplication,struct Windows::ApplicationModel::Core::ICoreApplication2,struct Windows::ApplicationModel::Core::ICoreApplication3,struct Windows::ApplicationModel::Core::ICoreApplicationExit,struct Windows::ApplicationModel::Core::ICoreImmersiveApplication,struct Windows::ApplicationModel::Core::ICoreImmersiveApplication2,struct Windows::ApplicationModel::Core::ICoreImmersiveApplication3,struct Windows::ApplicationModel::Core::ICoreApplicationUnhandledError,struct Microsoft::WRL::Implements<struct Microsoft::WRL::RuntimeClassFlags<3>,struct Microsoft::WRL::CloakedIid<struct Windows::ApplicationModel::Core::ICoreApplicationUseCount>,struct Microsoft::WRL::CloakedIid<struct IServiceProvider>,struct Microsoft::WRL::CloakedIid<struct IObjectWithSite>,struct Microsoft::WRL::CloakedIid<struct Windows::ApplicationModel::Infrastructure::ICoreApplicationInitializat()	Unknown	Symbols loaded.
 	Windows.UI.Xaml.dll!ctl::ComPtr<Windows::Foundation::Collections::VectorChangedEventHandler<IInspectable *>>::InternalRelease() Line 346	C++	Symbols loaded.
 	[Inline Frame] Windows.UI.Xaml.dll!ctl::ComPtr<Windows::ApplicationModel::Core::ICoreApplication2>::{dtor}() Line 345	C++	Symbols loaded.
 	Windows.UI.Xaml.dll!DirectUI::FrameworkApplication::HookBackgroundActivationEvents(bool fRegister=false) Line 1233	C++	Symbols loaded.
 	Windows.UI.Xaml.dll!DirectUI::FrameworkApplication::~FrameworkApplication() Line 591	C++	Symbols loaded.
 	Windows.UI.Xaml.dll!ctl::ComObject<DirectUI::FrameworkApplication>::`scalar deleting destructor'(unsigned int)	C++	Symbols loaded.
 	Windows.UI.Xaml.dll!ctl::ComBase::ReleaseImpl() Line 307	C++	Symbols loaded.
 	[Inline Frame] TerminalApp.dll!winrt::Windows::Foundation::IUnknown::release_ref() Line 2161	C++	Symbols loaded.
 	[Inline Frame] TerminalApp.dll!winrt::Windows::Foundation::IUnknown::{dtor}() Line 2066	C++	Symbols loaded.
 	TerminalApp.dll!winrt::impl::root_implements<winrt::TerminalApp::implementation::PaletteItemTemplateSelector,winrt::TerminalApp::PaletteItemTemplateSelector,winrt::composing,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides2>::~root_implements<winrt::TerminalApp::implementation::PaletteItemTemplateSelector,winrt::TerminalApp::PaletteItemTemplateSelector,winrt::composing,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides2>() Line 7527	C++	Symbols loaded.
 	TerminalApp.dll!winrt::TerminalApp::implementation::App::`scalar deleting destructor'(unsigned int)	C++	Non-user code. Symbols loaded.
 	TerminalApp.dll!winrt::impl::produce_base<winrt::TerminalApp::implementation::App,winrt::TerminalApp::IApp,void>::Release() Line 7152	C++	Symbols loaded.
 	Windows.UI.Xaml.dll!ctl::release_interface<DirectUI::FrameworkApplication>(DirectUI::FrameworkApplication * & pInterface=0x000002c37f81c600) Line 137	C++	Non-user code. Symbols loaded.
 	[Inline Frame] Windows.UI.Xaml.dll!DirectUI::FrameworkApplication::GlobalDeinit() Line 668	C++	Non-user code. Symbols loaded.
 	Windows.UI.Xaml.dll!DeinitializeDll() Line 319	C++	Non-user code. Symbols loaded.
 	Windows.UI.Xaml.dll!DllMain(HINSTANCE__ * hinstDLL, unsigned int fdwReason, void * __formal) Line 394	C++	Non-user code. Symbols loaded.
 	Windows.UI.Xaml.dll!dllmain_dispatch(HINSTANCE__ * const instance=0x00007ff919460000, const unsigned long reason=0, void * const reserved=0x0000000000000001) Line 200	C++	Non-user code. Symbols loaded.
 	ntdll.dll!LdrpCallInitRoutine()	Unknown	Non-user code. Symbols loaded without source information.
 	ntdll.dll!LdrShutdownProcess()	Unknown	Non-user code. Symbols loaded without source information.
 	ntdll.dll!RtlExitUserProcess()	Unknown	Non-user code. Symbols loaded without source information.
 	kernel32.dll!ExitProcessImplementation()	Unknown	Non-user code. Symbols loaded without source information.
 	ucrtbase.dll!exit_or_terminate_process()	Unknown	Non-user code. Symbols loaded without source information.
 	ucrtbase.dll!common_exit()	Unknown	Non-user code. Symbols loaded without source information.
 	WindowsTerminal.exe!__scrt_common_main_seh() Line 295	C++	Non-user code. Symbols loaded.
 	kernel32.dll!BaseThreadInitThunk()	Unknown	Non-user code. Symbols loaded without source information.
 	ntdll.dll!RtlUserThreadStart()	Unknown	Non-user code. Symbols loaded without source information.

After closing the error dialog everything works normally.

Originally created by @alabuzhev on GitHub (May 23, 2023). ### Windows Terminal version 1.18.1421.0 ### Windows build number 10.0.19045.2728 ### Other Software N/A ### Steps to reproduce This is probably related to > All instances of Windows Terminal now run in the same process (https://github.com/microsoft/terminal/pull/14843) 1. Run WT. 2. Run WT again. ### Expected Behavior Two WT windows ### Actual Behavior Two WT windows and an extra error dialog: ![image](https://github.com/microsoft/terminal/assets/11453922/562626af-a480-4c5b-9e7f-d48ae718144f) ![image](https://github.com/microsoft/terminal/assets/11453922/f0ea0571-025c-4b7b-bbf4-0130f73ebf36) Stack trace: ``` > twinapi.appcore.dll!Microsoft::WRL::ActivationFactory<struct Microsoft::WRL::Implements<struct Microsoft::WRL::RuntimeClassFlags<3>,struct Windows::ApplicationModel::Core::ICoreApplication,struct Windows::ApplicationModel::Core::ICoreApplication2,struct Windows::ApplicationModel::Core::ICoreApplication3,struct Windows::ApplicationModel::Core::ICoreApplicationExit,struct Windows::ApplicationModel::Core::ICoreImmersiveApplication,struct Windows::ApplicationModel::Core::ICoreImmersiveApplication2,struct Windows::ApplicationModel::Core::ICoreImmersiveApplication3,struct Windows::ApplicationModel::Core::ICoreApplicationUnhandledError,struct Microsoft::WRL::Implements<struct Microsoft::WRL::RuntimeClassFlags<3>,struct Microsoft::WRL::CloakedIid<struct Windows::ApplicationModel::Core::ICoreApplicationUseCount>,struct Microsoft::WRL::CloakedIid<struct IServiceProvider>,struct Microsoft::WRL::CloakedIid<struct IObjectWithSite>,struct Microsoft::WRL::CloakedIid<struct Windows::ApplicationModel::Infrastructure::ICoreApplicationInitializat() Unknown Symbols loaded. Windows.UI.Xaml.dll!ctl::ComPtr<Windows::Foundation::Collections::VectorChangedEventHandler<IInspectable *>>::InternalRelease() Line 346 C++ Symbols loaded. [Inline Frame] Windows.UI.Xaml.dll!ctl::ComPtr<Windows::ApplicationModel::Core::ICoreApplication2>::{dtor}() Line 345 C++ Symbols loaded. Windows.UI.Xaml.dll!DirectUI::FrameworkApplication::HookBackgroundActivationEvents(bool fRegister=false) Line 1233 C++ Symbols loaded. Windows.UI.Xaml.dll!DirectUI::FrameworkApplication::~FrameworkApplication() Line 591 C++ Symbols loaded. Windows.UI.Xaml.dll!ctl::ComObject<DirectUI::FrameworkApplication>::`scalar deleting destructor'(unsigned int) C++ Symbols loaded. Windows.UI.Xaml.dll!ctl::ComBase::ReleaseImpl() Line 307 C++ Symbols loaded. [Inline Frame] TerminalApp.dll!winrt::Windows::Foundation::IUnknown::release_ref() Line 2161 C++ Symbols loaded. [Inline Frame] TerminalApp.dll!winrt::Windows::Foundation::IUnknown::{dtor}() Line 2066 C++ Symbols loaded. TerminalApp.dll!winrt::impl::root_implements<winrt::TerminalApp::implementation::PaletteItemTemplateSelector,winrt::TerminalApp::PaletteItemTemplateSelector,winrt::composing,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides2>::~root_implements<winrt::TerminalApp::implementation::PaletteItemTemplateSelector,winrt::TerminalApp::PaletteItemTemplateSelector,winrt::composing,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides,winrt::Windows::UI::Xaml::Controls::IDataTemplateSelectorOverrides2>() Line 7527 C++ Symbols loaded. TerminalApp.dll!winrt::TerminalApp::implementation::App::`scalar deleting destructor'(unsigned int) C++ Non-user code. Symbols loaded. TerminalApp.dll!winrt::impl::produce_base<winrt::TerminalApp::implementation::App,winrt::TerminalApp::IApp,void>::Release() Line 7152 C++ Symbols loaded. Windows.UI.Xaml.dll!ctl::release_interface<DirectUI::FrameworkApplication>(DirectUI::FrameworkApplication * & pInterface=0x000002c37f81c600) Line 137 C++ Non-user code. Symbols loaded. [Inline Frame] Windows.UI.Xaml.dll!DirectUI::FrameworkApplication::GlobalDeinit() Line 668 C++ Non-user code. Symbols loaded. Windows.UI.Xaml.dll!DeinitializeDll() Line 319 C++ Non-user code. Symbols loaded. Windows.UI.Xaml.dll!DllMain(HINSTANCE__ * hinstDLL, unsigned int fdwReason, void * __formal) Line 394 C++ Non-user code. Symbols loaded. Windows.UI.Xaml.dll!dllmain_dispatch(HINSTANCE__ * const instance=0x00007ff919460000, const unsigned long reason=0, void * const reserved=0x0000000000000001) Line 200 C++ Non-user code. Symbols loaded. ntdll.dll!LdrpCallInitRoutine() Unknown Non-user code. Symbols loaded without source information. ntdll.dll!LdrShutdownProcess() Unknown Non-user code. Symbols loaded without source information. ntdll.dll!RtlExitUserProcess() Unknown Non-user code. Symbols loaded without source information. kernel32.dll!ExitProcessImplementation() Unknown Non-user code. Symbols loaded without source information. ucrtbase.dll!exit_or_terminate_process() Unknown Non-user code. Symbols loaded without source information. ucrtbase.dll!common_exit() Unknown Non-user code. Symbols loaded without source information. WindowsTerminal.exe!__scrt_common_main_seh() Line 295 C++ Non-user code. Symbols loaded. kernel32.dll!BaseThreadInitThunk() Unknown Non-user code. Symbols loaded without source information. ntdll.dll!RtlUserThreadStart() Unknown Non-user code. Symbols loaded without source information. ``` After closing the error dialog everything works normally.
claunia added the Needs-TriageIssue-BugIn-PR labels 2026-01-31 06:58:02 +00:00
Author
Owner

@zadjii-msft commented on GitHub (May 23, 2023):

Hmmmmmm. When this happens, are there two windowsterminal.exe processes running in Task Manager? Any ideas which the error is coming from?

@zadjii-msft commented on GitHub (May 23, 2023): Hmmmmmm. When this happens, are there two windowsterminal.exe processes running in Task Manager? Any ideas which the error is coming from?
Author
Owner

@lhecker commented on GitHub (May 23, 2023):

I wonder if we need to pump the message loop on the main thread similarly to how we do it for each window thread. This does seem to be an after effect of us calling detach_abi on the _app though... 🤔

@lhecker commented on GitHub (May 23, 2023): I wonder if we need to pump the message loop on the main thread similarly to how we do it for each window thread. This does seem to be an after effect of us calling `detach_abi` on the `_app` though... 🤔
Author
Owner

@alabuzhev commented on GitHub (May 23, 2023):

are there two windowsterminal.exe processes running in Task Manager?

Three actually.

After the first run:

image

After the second run:

image

Any ideas which the error is coming from?

The second parent (PID 7528 on the screenshot). At least it is the one VS attaches to.

@alabuzhev commented on GitHub (May 23, 2023): > are there two windowsterminal.exe processes running in Task Manager? Three actually. After the first run: ![image](https://github.com/microsoft/terminal/assets/11453922/c297d2bd-a0df-45ae-9454-4626e002ed1a) After the second run: ![image](https://github.com/microsoft/terminal/assets/11453922/001f5d71-0716-4c2c-8ad9-187ab0800a38) > Any ideas which the error is coming from? The second parent (PID 7528 on the screenshot). At least it is the one VS attaches to.
Author
Owner

@alabuzhev commented on GitHub (May 23, 2023):

P.S. I think Windows doesn't show the "app has stopped working" dialog by default these days, maybe this is why it got overlooked. The error should still be in the event log under "administrative events" and the the dialog can be re-enabled in group policy.

@alabuzhev commented on GitHub (May 23, 2023): P.S. I think Windows doesn't show the "app has stopped working" dialog by default these days, maybe this is why it got overlooked. The error should still be in the event log under "administrative events" and the the dialog can be re-enabled in [group policy](https://superuser.com/questions/1246626/is-it-by-design-that-windows-10-no-longer-displays-app-has-stopped-working-d/1349113#1349113).
Author
Owner

@zadjii-msft commented on GitHub (May 24, 2023):

Huh. So the wt that handed off to the main instance, crashed when it died (of natural causes). And it crashed... dtoring our App? And what the heck is that TerminalApp.dll!winrt::impl::root_implements<winrt::TerminalApp::implementation::PaletteItemTemplateSelector frame doing there?

Maybe this regressed in #15397. But I almost don't think that's right - we shouldn't have even made a window in that process which we could leak.

I think Windows doesn't show the "app has stopped working" dialog by default these days, maybe this is why it got overlooked

FWIW I pretty much always run with "post-mortem debugging" enabled for WinDbg. So usually we catch things like this.

@zadjii-msft commented on GitHub (May 24, 2023): Huh. So the `wt` that handed off to the main instance, crashed when it died (of natural causes). And it crashed... dtoring our `App`? And what the heck is that `TerminalApp.dll!winrt::impl::root_implements<winrt::TerminalApp::implementation::PaletteItemTemplateSelector` frame doing there? _Maybe_ this regressed in #15397. But I almost don't think that's right - we shouldn't have even made a window in that process which we could leak. > I think Windows doesn't show the "app has stopped working" dialog by default these days, maybe this is why it got overlooked FWIW I pretty much always run with "post-mortem debugging" enabled for WinDbg. So usually we catch things like this.
Author
Owner

@zadjii-msft commented on GitHub (May 24, 2023):

Hmm. I can repro this in a VM - even on the build with the leak taken out. So it's not that.

er, no, this was useless

There's a stashed exception in there:

  Name Value Type
$exceptionstack [9 Frames, Microsoft.Terminal.Remoting.dll!winrt::impl::consume_Microsoft_Terminal_Remoting_IMonarchwinrt::Microsoft::Terminal::Remoting::IMonarch::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args) Line 122]  
  [0] [External Code] void*
  [1] Microsoft.Terminal.Remoting.dll!winrt::impl::consume_Microsoft_Terminal_Remoting_IMonarchwinrt::Microsoft::Terminal::Remoting::IMonarch::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args) Line 122 void*
  [2] Microsoft.Terminal.Remoting.dll!winrt::Microsoft::Terminal::Remoting::implementation::WindowManager::_proposeToMonarch(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args) Line 272 void*
  [3] Microsoft.Terminal.Remoting.dll!winrt::Microsoft::Terminal::Remoting::implementation::WindowManager::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args, const bool isolatedMode) Line 135 void*
  [4] Microsoft.Terminal.Remoting.dll!winrt::impl::producewinrt::Microsoft::Terminal::Remoting::implementation::WindowManager,winrt::Microsoft::Terminal::Remoting::IWindowManager::ProposeCommandline(void * args, bool isolatedMode, void * * result) Line 1947 void*
  [5] WindowsTerminal.exe!winrt::impl::consume_Microsoft_Terminal_Remoting_IWindowManagerwinrt::Microsoft::Terminal::Remoting::IWindowManager::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args, bool isolatedMode) Line 752 void*
  [6] WindowsTerminal.exe!WindowEmperor::HandleCommandlineArgs() Line 117 void*
  [7] WindowsTerminal.exe!wWinMain(HINSTANCE__ * formal, HINSTANCE * __formal, wchar_t * __formal, int __formal) Line 118 void*
  [8] [External Code] void*
@zadjii-msft commented on GitHub (May 24, 2023): Hmm. I can repro this in a VM - even on the build with the leak taken out. So it's not that. <details> <summary>er, no, this was useless</summary> There's a stashed exception in there:   | Name | Value | Type -- | -- | -- | -- ◢ | $exceptionstack | [9 Frames, Microsoft.Terminal.Remoting.dll!winrt::impl::consume_Microsoft_Terminal_Remoting_IMonarch<winrt::Microsoft::Terminal::Remoting::IMonarch>::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args) Line 122] |     | [0] | [External Code] | void*   | [1] | Microsoft.Terminal.Remoting.dll!winrt::impl::consume_Microsoft_Terminal_Remoting_IMonarch<winrt::Microsoft::Terminal::Remoting::IMonarch>::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args) Line 122 | void*   | [2] | Microsoft.Terminal.Remoting.dll!winrt::Microsoft::Terminal::Remoting::implementation::WindowManager::_proposeToMonarch(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args) Line 272 | void*   | [3] | Microsoft.Terminal.Remoting.dll!winrt::Microsoft::Terminal::Remoting::implementation::WindowManager::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args, const bool isolatedMode) Line 135 | void*   | [4] | Microsoft.Terminal.Remoting.dll!winrt::impl::produce<winrt::Microsoft::Terminal::Remoting::implementation::WindowManager,winrt::Microsoft::Terminal::Remoting::IWindowManager>::ProposeCommandline(void * args, bool isolatedMode, void * * result) Line 1947 | void*   | [5] | WindowsTerminal.exe!winrt::impl::consume_Microsoft_Terminal_Remoting_IWindowManager<winrt::Microsoft::Terminal::Remoting::IWindowManager>::ProposeCommandline(const winrt::Microsoft::Terminal::Remoting::CommandlineArgs & args, bool isolatedMode) Line 752 | void*   | [6] | WindowsTerminal.exe!WindowEmperor::HandleCommandlineArgs() Line 117 | void*   | [7] | WindowsTerminal.exe!wWinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, wchar_t * __formal, int __formal) Line 118 | void*   | [8] | [External Code] | void* </details>
Author
Owner

@zadjii-msft commented on GitHub (May 24, 2023):

I hate it so much

diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp
index a268dfd59..1bb8b2711 100644
--- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp
+++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp
@@ -41,10 +41,30 @@ WindowEmperor::WindowEmperor() noexcept :

 WindowEmperor::~WindowEmperor()
 {
+    if (_app)^M
     _app.Close();
     _app = nullptr;
 }

+static bool IsWindows11()^M
+{^M
+    static const bool isWindows11 = []() {^M
+        OSVERSIONINFOEXW osver{};^M
+        osver.dwOSVersionInfoSize = sizeof(osver);^M
+        osver.dwBuildNumber = 22000;^M
+^M
+        DWORDLONG dwlConditionMask = 0;^M
+        VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);^M
+^M
+        if (VerifyVersionInfoW(&osver, VER_BUILDNUMBER, dwlConditionMask) != FALSE)^M
+        {^M
+            return true;^M
+        }^M
+        return false;^M
+    }();^M
+    return isWindows11;^M
+}^M
+^M
 void _buildArgsFromCommandline(std::vector<winrt::hstring>& args)
 {
     if (auto commandline{ GetCommandLineW() })
@@ -97,7 +117,8 @@ bool WindowEmperor::HandleCommandlineArgs()

     const auto result = _manager.ProposeCommandline(eventArgs, isolatedMode);

-    if (result.ShouldCreateWindow())
+    const bool makeWindow = result.ShouldCreateWindow();^M
+    if (makeWindow)^M
     {
         _createNewWindowThread(Remoting::WindowRequestedArgs{ result, eventArgs });

@@ -111,9 +132,15 @@ bool WindowEmperor::HandleCommandlineArgs()
             AppHost::s_DisplayMessageBox(res);
             ExitThread(res.ExitCode);
         }
+^M
+        if (!IsWindows11())^M
+        {^M
+            auto a{ _app };^M
+            winrt::detach_abi(_app);^M
+        }^M
     }

-    return result.ShouldCreateWindow();
+    return makeWindow;^M
 }
@zadjii-msft commented on GitHub (May 24, 2023): I hate it so much ```diff diff --git a/src/cascadia/WindowsTerminal/WindowEmperor.cpp b/src/cascadia/WindowsTerminal/WindowEmperor.cpp index a268dfd59..1bb8b2711 100644 --- a/src/cascadia/WindowsTerminal/WindowEmperor.cpp +++ b/src/cascadia/WindowsTerminal/WindowEmperor.cpp @@ -41,10 +41,30 @@ WindowEmperor::WindowEmperor() noexcept : WindowEmperor::~WindowEmperor() { + if (_app)^M _app.Close(); _app = nullptr; } +static bool IsWindows11()^M +{^M + static const bool isWindows11 = []() {^M + OSVERSIONINFOEXW osver{};^M + osver.dwOSVersionInfoSize = sizeof(osver);^M + osver.dwBuildNumber = 22000;^M +^M + DWORDLONG dwlConditionMask = 0;^M + VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);^M +^M + if (VerifyVersionInfoW(&osver, VER_BUILDNUMBER, dwlConditionMask) != FALSE)^M + {^M + return true;^M + }^M + return false;^M + }();^M + return isWindows11;^M +}^M +^M void _buildArgsFromCommandline(std::vector<winrt::hstring>& args) { if (auto commandline{ GetCommandLineW() }) @@ -97,7 +117,8 @@ bool WindowEmperor::HandleCommandlineArgs() const auto result = _manager.ProposeCommandline(eventArgs, isolatedMode); - if (result.ShouldCreateWindow()) + const bool makeWindow = result.ShouldCreateWindow();^M + if (makeWindow)^M { _createNewWindowThread(Remoting::WindowRequestedArgs{ result, eventArgs }); @@ -111,9 +132,15 @@ bool WindowEmperor::HandleCommandlineArgs() AppHost::s_DisplayMessageBox(res); ExitThread(res.ExitCode); } +^M + if (!IsWindows11())^M + {^M + auto a{ _app };^M + winrt::detach_abi(_app);^M + }^M } - return result.ShouldCreateWindow(); + return makeWindow;^M } ```
Author
Owner

@zadjii-msft commented on GitHub (May 24, 2023):

That horrible diff will "leak" the App on Windows 10. "Leak" in quotes, because the whole process is exiting, so the entire thing is just gonna get released instantly after that when the process is exited.

And you wanna know what? We used to do that intentionally. See #5629.

We actually still do leak it intentionally. Problem is, we only leak it for the "monarch" process, the main one, with the windows. The other peasant process that just immediately fucks off - that one doesn't leak and GUESS WHAT. That crashes. Cause of course it does.

@zadjii-msft commented on GitHub (May 24, 2023): That horrible diff will "leak" the `App` on Windows 10. "Leak" in quotes, because the whole process is exiting, so the entire thing is just gonna get released instantly after that when the process is exited. And you wanna know what? We _used to do that intentionally_. See #5629. We actually still do leak it intentionally. Problem is, we only leak it for the "monarch" process, the main one, with the windows. The other peasant process that just immediately fucks off - that one doesn't leak and GUESS WHAT. That crashes. Cause of course it does.
Author
Owner

@alabuzhev commented on GitHub (May 24, 2023):

Wait

So you have a system where random peasants just delegate all the work to the "monarch" and call it a day? 😄

@alabuzhev commented on GitHub (May 24, 2023): <details> <summary>Wait</summary> So you have a system where random peasants just delegate all the work to the "monarch" and call it a day? 😄 </details>
Author
Owner

@zadjii-msft commented on GitHub (May 24, 2023):

So you have a system where random peasants just delegate all the work to the "monarch" and call it a day

SURE DO

Monarch and Peasant Processes

This document assumes the reader is already familiar with the "Monarch and
Peasant" architecture as detailed in the Windows Terminal Process Model 2.0
Spec
. As a quick summary:

  • Every Windows Terminal window is a "Peasant" process.
  • One of the Windows Terminal window processes is also the "Monarch" process.
    The Monarch is picked randomly from the Terminal windows, and there is only
    ever one Monarch process at a time.
  • Peasants can communicate with the monarch when certain state changes (such as
    their window being activated), and the monarch can send commands to any of the
    peasants.

Admittedly, Process Model v2 never shipped, because what we ended up shipping, "process model v3" was way easier to implement, and I never went back to update that doc. But the Monarch/Peasant stuff all stayed.

@zadjii-msft commented on GitHub (May 24, 2023): > So you have a system where random peasants just delegate all the work to the "monarch" and call it a day [SURE DO](https://github.com/microsoft/terminal/blob/main/doc/specs/%235000%20-%20Process%20Model%202.0/%234472%20-%20Windows%20Terminal%20Session%20Management.md#monarch-and-peasant-processes) > ### Monarch and Peasant Processes > > This document assumes the reader is already familiar with the "Monarch and > Peasant" architecture as detailed in the [Windows Terminal Process Model 2.0 > Spec](https://github.com/microsoft/terminal/blob/main/doc/specs/%235000%20-%20Process%20Model%202.0/%235000%20-%20Process%20Model%202.0.md). As a quick summary: > > * Every Windows Terminal window is a "Peasant" process. > * One of the Windows Terminal window processes is also the "Monarch" process. > The Monarch is picked randomly from the Terminal windows, and there is only > ever one Monarch process at a time. > * Peasants can communicate with the monarch when certain state changes (such as > their window being activated), and the monarch can send commands to any of the > peasants. > Admittedly, Process Model v2 never shipped, because what we ended up shipping, "process model v3" was way easier to implement, and I never went back to update that doc. But the Monarch/Peasant stuff all stayed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19938