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

Another exception on close, maybe not a crash? #11684

Closed
zadjii-msft opened this issue Nov 4, 2021 · 3 comments · Fixed by #11857
Closed

Another exception on close, maybe not a crash? #11684

zadjii-msft opened this issue Nov 4, 2021 · 3 comments · Fixed by #11857
Labels
Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.

Comments

@zadjii-msft
Copy link
Member

This one seems to hit 100% for me in Debug builds, currently on 1167e20 but I'd bet this is in main.

Repro:

  • Open a debug Terminal in vs
  • Persist layouts is off, not sure it matters.
  • close the window with the 'x'
  • experience crash

Likely regressed in #11440, this line: https://github.com/microsoft/terminal/pull/11440/files#diff-d9af234d6dd21db9240dc3733d69471898a79f1c4386cb3c48ac45ab7158cd07R405

AppHost::LastTabClosed RESETS the _getWindowLayoutThrottler, then calls SignalClose(). That goes up and back down to the _windowManager.WindowClosed handler set up in AppHost::_BecomeMonarch. At this point, _getWindowLayoutThrottler DOESN'T HAVE A VALUE, so

_getWindowLayoutThrottler.value()()

causes a std::bad_optional_access exception.

I don't know if this is a crash, or just a first-chance exception that VS is reporting that doesn't matter. It's definitely a bug though.

Stack
 	WindowsTerminal.exe!<lambda_d14224e5f61d340d2454360bff63413e>::operator()<winrt::Windows::Foundation::IInspectable const &,winrt::Windows::Foundation::IInspectable const &>(const winrt::Windows::Foundation::IInspectable & __formal, const winrt::Windows::Foundation::IInspectable & __formal) Line 818	C++
 	WindowsTerminal.exe!winrt::impl::delegate<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>,<lambda_d14224e5f61d340d2454360bff63413e>>::Invoke(void * sender, void * args) Line 895	C++
 	Microsoft.Terminal.Remoting.dll!winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>::operator()(const winrt::Windows::Foundation::IInspectable & sender, const winrt::Windows::Foundation::IInspectable & args) Line 2525	C++
 	Microsoft.Terminal.Remoting.dll!winrt::impl::invoke<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>,winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>(const winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable> & delegate, const winrt::Windows::Foundation::IInspectable & <args_0>, const winrt::Windows::Foundation::IInspectable & <args_1>) Line 5762	C++
 	Microsoft.Terminal.Remoting.dll!winrt::event<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>>::operator()<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>(const winrt::Windows::Foundation::IInspectable & <args_0>, const winrt::Windows::Foundation::IInspectable & <args_1>) Line 5897	C++
 	Microsoft.Terminal.Remoting.dll!<lambda_feabb5633168b9dfc8d0e9799de5ebe0>::operator()<winrt::Windows::Foundation::IInspectable const &,winrt::Windows::Foundation::IInspectable const &>(const winrt::Windows::Foundation::IInspectable & <args_0>, const winrt::Windows::Foundation::IInspectable & <args_1>) Line 2520	C++
 	Microsoft.Terminal.Remoting.dll!winrt::impl::delegate<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>,<lambda_feabb5633168b9dfc8d0e9799de5ebe0>>::Invoke(void * sender, void * args) Line 895	C++
 	Microsoft.Terminal.Remoting.dll!winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>::operator()(const winrt::Windows::Foundation::IInspectable & sender, const winrt::Windows::Foundation::IInspectable & args) Line 2525	C++
 	Microsoft.Terminal.Remoting.dll!winrt::impl::invoke<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>,std::nullptr_t,std::nullptr_t>(const winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable> & delegate, void * const & <args_0>, void * const & <args_1>) Line 5762	C++
 	Microsoft.Terminal.Remoting.dll!winrt::event<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::Windows::Foundation::IInspectable>>::operator()<std::nullptr_t,std::nullptr_t>(void * const & <args_0>, void * const & <args_1>) Line 5897	C++
 	Microsoft.Terminal.Remoting.dll!winrt::Microsoft::Terminal::Remoting::implementation::Monarch::SignalClose(const unsigned __int64 peasantId) Line 212	C++
 	Microsoft.Terminal.Remoting.dll!winrt::impl::produce<winrt::Microsoft::Terminal::Remoting::implementation::Monarch,winrt::Microsoft::Terminal::Remoting::IMonarch>::SignalClose(unsigned __int64 peasantId) Line 999	C++
 	Microsoft.Terminal.Remoting.dll!winrt::impl::consume_Microsoft_Terminal_Remoting_IMonarch<winrt::Microsoft::Terminal::Remoting::IMonarch>::SignalClose(unsigned __int64 peasantId) Line 117	C++
 	Microsoft.Terminal.Remoting.dll!winrt::Microsoft::Terminal::Remoting::implementation::WindowManager::SignalClose() Line 74	C++
 	Microsoft.Terminal.Remoting.dll!winrt::impl::produce<winrt::Microsoft::Terminal::Remoting::implementation::WindowManager,winrt::Microsoft::Terminal::Remoting::IWindowManager>::SignalClose() Line 1710	C++
 	WindowsTerminal.exe!winrt::impl::consume_Microsoft_Terminal_Remoting_IWindowManager<winrt::Microsoft::Terminal::Remoting::IWindowManager>::SignalClose() Line 655	C++
>	WindowsTerminal.exe!AppHost::LastTabClosed(const winrt::Windows::Foundation::IInspectable & __formal, const winrt::TerminalApp::LastTabClosedEventArgs & __formal) Line 412	C++
 	WindowsTerminal.exe!<lambda_3930e0e5f7a1efe801e738623725cca1>::operator()<winrt::Windows::Foundation::IInspectable const &,winrt::TerminalApp::LastTabClosedEventArgs const &>(const winrt::Windows::Foundation::IInspectable & <args_0>, const winrt::TerminalApp::LastTabClosedEventArgs & <args_1>) Line 2512	C++
 	WindowsTerminal.exe!winrt::impl::delegate<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::TerminalApp::LastTabClosedEventArgs>,<lambda_3930e0e5f7a1efe801e738623725cca1>>::Invoke(void * sender, void * args) Line 895	C++
 	TerminalApp.dll!winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::TerminalApp::LastTabClosedEventArgs>::operator()(const winrt::Windows::Foundation::IInspectable & sender, const winrt::TerminalApp::LastTabClosedEventArgs & args) Line 2525	C++
 	TerminalApp.dll!winrt::impl::invoke<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::TerminalApp::LastTabClosedEventArgs>,winrt::TerminalApp::implementation::TerminalPage,std::nullptr_t>(const winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::TerminalApp::LastTabClosedEventArgs> & delegate, const winrt::TerminalApp::implementation::TerminalPage & <args_0>, void * const & <args_1>) Line 5762	C++
 	TerminalApp.dll!winrt::event<winrt::Windows::Foundation::TypedEventHandler<winrt::Windows::Foundation::IInspectable,winrt::TerminalApp::LastTabClosedEventArgs>>::operator()<winrt::TerminalApp::implementation::TerminalPage,std::nullptr_t>(const winrt::TerminalApp::implementation::TerminalPage & <args_0>, void * const & <args_1>) Line 5897	C++
 	TerminalApp.dll!winrt::TerminalApp::implementation::TerminalPage::_RemoveTab(const winrt::TerminalApp::TabBase & tab) Line 528	C++
 	TerminalApp.dll!winrt::TerminalApp::implementation::TerminalPage::_HandleCloseTabRequested$_ResumeCoro$1() Line 478	C++
 	[External Code]	
 	TerminalApp.dll!winrt::TerminalApp::implementation::TerminalPage::_RemoveTabs$_ResumeCoro$1() Line 814	C++
 	[External Code]	
 	TerminalApp.dll!winrt::TerminalApp::implementation::TerminalPage::_RemoveAllTabs() Line 1053	C++
 	TerminalApp.dll!winrt::TerminalApp::implementation::TerminalPage::CloseWindow$_ResumeCoro$1() Line 1406	C++
 	[External Code]	
 	TerminalApp.dll!winrt::TerminalApp::implementation::AppLogic::CloseWindow(winrt::Microsoft::Terminal::Settings::Model::LaunchPosition pos) Line 1178	C++
 	TerminalApp.dll!winrt::impl::produce<winrt::TerminalApp::implementation::AppLogic,winrt::TerminalApp::IAppLogic>::CloseWindow(winrt::impl::struct_Microsoft_Terminal_Settings_Model_LaunchPosition position) Line 2764	C++
 	WindowsTerminal.exe!winrt::impl::consume_TerminalApp_IAppLogic<winrt::TerminalApp::IAppLogic>::CloseWindow(const winrt::Microsoft::Terminal::Settings::Model::LaunchPosition & position) Line 245	C++
 	WindowsTerminal.exe!AppHost::Initialize::__l2::<lambda>() Line 310	C++
 	WindowsTerminal.exe!winrt::impl::variadic_delegate<void <lambda>(void),void>::invoke() Line 5316	C++
 	WindowsTerminal.exe!winrt::impl::delegate_base<void>::operator()() Line 5385	C++
 	WindowsTerminal.exe!winrt::impl::invoke<winrt::delegate<>>(const winrt::delegate<> & delegate) Line 5762	C++
 	WindowsTerminal.exe!winrt::event<winrt::delegate<>>::operator()<>() Line 5897	C++
 	WindowsTerminal.exe!IslandWindow::MessageHandler(const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 493	C++
 	WindowsTerminal.exe!NonClientIslandWindow::MessageHandler(const unsigned int message, const unsigned __int64 wParam, const __int64 lParam) Line 910	C++
 	WindowsTerminal.exe!BaseWindow<IslandWindow>::WndProc(HWND__ * const window, const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 35	C++
 	[External Code]	
 	WindowsTerminal.exe!BaseWindow<IslandWindow>::MessageHandler(const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 97	C++
 	WindowsTerminal.exe!IslandWindow::MessageHandler(const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 625	C++
 	WindowsTerminal.exe!NonClientIslandWindow::MessageHandler(const unsigned int message, const unsigned __int64 wParam, const __int64 lParam) Line 910	C++
 	WindowsTerminal.exe!BaseWindow<IslandWindow>::WndProc(HWND__ * const window, const unsigned int message, const unsigned __int64 wparam, const __int64 lparam) Line 35	C++
 	[External Code]	
 	WindowsTerminal.exe!wWinMain(HINSTANCE__ * __formal, HINSTANCE__ * __formal, wchar_t * __formal, int __formal) Line 198	C++
 	[External Code]	

@zadjii-msft zadjii-msft added Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Priority-1 A description (P1) zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. labels Nov 4, 2021
@zadjii-msft zadjii-msft added this to the Terminal v1.13 milestone Nov 4, 2021
@ghost ghost added the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Nov 4, 2021
@zadjii-msft
Copy link
Member Author

There is a CATCH_LOG() at the bottom of WindowManager::SignalClose - still tho, seems like something we could clean up.

@Rosefield
Copy link
Contributor

Rosefield commented Nov 4, 2021

Yup, that makes sense and is definitely something I overlooked or didn't notice because of catching the exception, and the fact that I made it so calling quit didn't call the WindowClosed handlers. I apologize for the trouble.

I don't really have time to work on anything here for the next couple of weeks, but it can be solved in a number of ways

  1. just checking if the value is set before calling it
  2. removing the WindowClosed/WindowOpened handlers like the GetWindowLayout handler is removed here: https://github.com/microsoft/terminal/blob/main/src/cascadia/WindowsTerminal/AppHost.cpp#L406
  3. ???
  4. ripping up the whole things and starting over

Probably should also give some thought to the placement of SignalClose itself. Originally it was just called when the WindowManager ran its destructor, but of course in the linked PR I added it earlier in the closing process and so some of the assumptions have been broken.

@DHowett DHowett removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Nov 17, 2021
@ghost ghost added the In-PR This issue has a related PR label Dec 1, 2021
@ghost ghost closed this as completed in #11857 Dec 6, 2021
@ghost ghost removed the In-PR This issue has a related PR label Dec 6, 2021
ghost pushed a commit that referenced this issue Dec 6, 2021
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
Clean up an invalid access that I introduced in #11440 

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? --> 
## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #11684 
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed
@ghost ghost added the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Dec 6, 2021
DHowett pushed a commit that referenced this issue Dec 13, 2021
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? -->
## Summary of the Pull Request
Clean up an invalid access that I introduced in #11440

<!-- Other than the issue solved, is this relevant to any other issues/existing PRs? -->
## References

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist
* [x] Closes #11684
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Documentation updated. If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/terminal) and link it here: #xxx
* [ ] Schema updated.
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

<!-- Provide a more detailed description of the PR, other things fixed or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

(cherry picked from commit 29e6235)
@ghost
Copy link

ghost commented Dec 14, 2021

🎉This issue was addressed in #11857, which has now been successfully released as Windows Terminal Preview v1.12.3472.0.:tada:

Handy links:

@DHowett DHowett removed the zPreview-Service-Queued-1.13 A floating label that tracks the current Preview version for servicing purposes. label Jan 21, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Remoting Communication layer between windows. Often for windowing behavior, quake mode, etc. Help Wanted We encourage anyone to jump in on these. Issue-Bug It either shouldn't be doing this or needs an investigation. Priority-1 A description (P1) Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants