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

[1.21.1091 Canary] Terminal crashes on launch #17089

Closed
zadjii-msft opened this issue Apr 19, 2024 · 5 comments · Fixed by #17092
Closed

[1.21.1091 Canary] Terminal crashes on launch #17089

zadjii-msft opened this issue Apr 19, 2024 · 5 comments · Fixed by #17092
Labels
Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Severity-Blocking We won't ship a release like this! No-siree.

Comments

@zadjii-msft
Copy link
Member

Methinks it's an explosion in the merge between #16611 and #17067

Useless stack:

[0x3]   Microsoft_Terminal_Control!std::coroutine_traits<winrt::fire_and_forget,winrt::Microsoft::Terminal::Control::implementation::ControlCore &,std::basic_string_view<wchar_t,std::char_traits<wchar_t> >,unsigned int>::promise_type::unhandled_exception+0x9   0x61c3efc640   0x7fffe5b3a496   
[0x4]   Microsoft_Terminal_Control!`winrt::Microsoft::Terminal::Control::implementation::TermControl::_coreUpdateSearchResults$_ResumeCoro$1'::`1'::catch$57+0x26   0x61c3efc670   0x7fffe5b2fcd0   
[0x5]   Microsoft_Terminal_Control!_CallSettingFrame_LookupContinuationIndex+0x20   0x61c3efc6b0   0x7fffe5b2edf5   
[0x6]   Microsoft_Terminal_Control!__FrameHandler4::CxxCallCatchBlock+0x115   0x61c3efc6e0   0x7ff812f61d16   
[0x7]   ntdll!RtlCaptureContext2+0x4a6   0x61c3efc7c0   0x7fffe5b39fc8   
[0x8]   Microsoft_Terminal_Control!winrt::Microsoft::Terminal::Control::implementation::TermControl::_coreUpdateSearchResults$_ResumeCoro$1+0x278   0x61c3efee90   0x7fffe5b02170   
[0x9]   Microsoft_Terminal_Control!std::coroutine_handle<void>::resume+0xc   0x61c3efefd0   0x7ffff41d08f3   
[0xa]   Microsoft_Terminal_Control!wil::details::dispatcher_handler::Complete+0x1c   0x61c3efefd0   0x7ffff41d08f3   
[0xb]   Microsoft_Terminal_Control!wil::details::dispatcher_handler::operator()+0x1c   0x61c3efefd0   0x7ffff41d08f3   
[0xc]   Microsoft_Terminal_Control!winrt::impl::delegate<winrt::Windows::UI::Core::DispatchedHandler,wil::details::dispatcher_handler>::Invoke+0x20   0x61c3efefd0   0x7ffff41d08f3  

winrt::fire_and_forget TermControl::_coreUpdateSearchResults(const IInspectable& /*sender*/, Control::UpdateSearchResultsEventArgs args)
{
co_await wil::resume_foreground(Dispatcher());
if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this) })
{
automationPeer.RaiseNotificationEvent(
Automation::Peers::AutomationNotificationKind::ActionCompleted,
Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
args.FoundMatch() ? RS_(L"SearchBox_MatchesAvailable") : RS_(L"SearchBox_NoMatches"), // what to announce if results were found
L"SearchBoxResultAnnouncement" /* unique name for this group of notifications */);
}
_UpdateSearchScrollMarks();
if (_searchBox)
{
_searchBox->NavigationEnabled(true);
if (args.State() == Control::SearchState::Inactive)
{
_searchBox->ClearStatus();
}
else
{
_searchBox->SetStatus(args.TotalMatches(), args.CurrentMatch());
}
}
}

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Apr 19, 2024
@zadjii-msft
Copy link
Member Author

Okay first off: The automationPeer.RaiseNotificationEvent gets called... a lot, on startup. Before I've even opened the window. Shouldn't that get moved into if (_searchbox)?

@lhecker
Copy link
Member

lhecker commented Apr 19, 2024

We've discussed this over here: #16611 (comment)
I've just started making the changes necessary to fix that.

@zadjii-msft
Copy link
Member Author

Mmk, lemme know when you've got a fix ready.

My half assed fix was:

diff --git a/src/cascadia/TerminalControl/TermControl.cpp b/src/cascadia/TerminalControl/TermControl.cpp
index acab82931..1692a981a 100644
--- a/src/cascadia/TerminalControl/TermControl.cpp
+++ b/src/cascadia/TerminalControl/TermControl.cpp
@@ -3569,19 +3569,21 @@ namespace winrt::Microsoft::Terminal::Control::implementation
     winrt::fire_and_forget TermControl::_coreUpdateSearchResults(const IInspectable& /*sender*/, Control::UpdateSearchResultsEventArgs args)
     {
         co_await wil::resume_foreground(Dispatcher());
-        if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this) })
-        {
-            automationPeer.RaiseNotificationEvent(
-                Automation::Peers::AutomationNotificationKind::ActionCompleted,
-                Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
-                args.FoundMatch() ? RS_(L"SearchBox_MatchesAvailable") : RS_(L"SearchBox_NoMatches"), // what to announce if results were found
-                L"SearchBoxResultAnnouncement" /* unique name for this group of notifications */);
-        }

-        _UpdateSearchScrollMarks();

         if (_searchBox)
         {
+            if (auto automationPeer{ Automation::Peers::FrameworkElementAutomationPeer::FromElement(*this) })
+            {
+                automationPeer.RaiseNotificationEvent(
+                    Automation::Peers::AutomationNotificationKind::ActionCompleted,
+                    Automation::Peers::AutomationNotificationProcessing::ImportantMostRecent,
+                    args.FoundMatch() ? RS_(L"SearchBox_MatchesAvailable") : RS_(L"SearchBox_NoMatches"), // what to announce if results were found
+                    L"SearchBoxResultAnnouncement" /* unique name for this group of notifications */);
+            }
+
+            _UpdateSearchScrollMarks();
+
             _searchBox->NavigationEnabled(true);
             if (args.State() == Control::SearchState::Inactive)
             {

but I've got a consistent repro of the crash, so just lemme know

@AvogatoWizardWhisker
Copy link

Crash also occurs when I close Terminal, however it hangs then crashes.

image

@zadjii-msft zadjii-msft added this to the Terminal v1.21 milestone Apr 23, 2024
@zadjii-msft zadjii-msft added the Severity-Blocking We won't ship a release like this! No-siree. label Apr 23, 2024
@zadjii-msft
Copy link
Member Author

@AvogatoWizardWhisker can you file a new issue for that hang/crash on shutdown? adding your settings & state.json will probably be helpful for debugging. I want to make sure that gets sorted separately before the 1.21 release ☺️

github-merge-queue bot pushed a commit that referenced this issue Apr 23, 2024
This PR extends `til::throttled_func` to also support debouncing:
* throttling: "At most 1 call every N seconds"
* debouncing: "Exactly 1 call after N seconds of inactivity"

Based on the latter the following series of changes were made:
* An `OutputIdle` event was added to `ControlCore` which is
  raised once there hasn't been any incoming data in 100ms.
  This also triggers an update of our regex patterns (URL detection).
* The event is then caught by `TermControl` which calls `Search()`.
* `Search()` in turn was modified to return its results by-value
  as a struct, which avoids the need for a search-update event
  and simplifies how we update the UI.

This architectural change, most importantly the removal of the
`TextLayoutUpdated` event, fixes a DoS bug in Windows Terminal:
As the event leads to UI thread activity, printing lots of text
continuously results in the UI thread becoming unresponsive.

On top of these, a number of improvements were made:
* `IRenderEngine::InvalidateHighlight` was changed to take the
  `TextBuffer` by-reference which avoids the need to accumulate the
  line renditions in a `std::vector` first. This improves Debug build
  performance during reflow by what I guess must be roughly
  a magnitude faster. This difference is very noticeable.
* When closing the search box, `ClearSearch()` is called to remove
  the highlights. The search text is restored when it's reopened,
  however the current search position isn't.

Closes #17073
Closes #17089

## Validation Steps Performed
* UIA announcements:
  * Pressing Ctrl+Shift+F the first time does not lead to one ✅
  * Typing the first letter does ✅
  * Closing doesn't ✅
  * Reopening does (as it restores the letter) ✅
* Closing the search box dismisses the highlights ✅
* Resizing the window recalculates the highlights ✅
* Changing the terminal output while the box is open
  recalculates the highlights ✅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs-Tag-Fix Doesn't match tag requirements Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Severity-Blocking We won't ship a release like this! No-siree.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants