Crash in OnAppInitialized #19989

Closed
opened 2026-01-31 06:59:42 +00:00 by claunia · 3 comments
Owner

Originally created by @zadjii-msft on GitHub (May 26, 2023).

Two bugs, pretty sure same root cause. I believe this is collectively 21% of the crashes in 1.18 so far.

  • MSFT:44725712 "WindowsTerminal.exe!NonClientIslandWindow::OnSize"
  • MSFT:44754014 "NonClientIslandWindow::GetTotalNonClientExclusiveSize"

Both have stacks north of WindowsTerminal.exe!AppHost::_WindowInitializedHandler$_ResumeCoro$

3c3b1aac02/src/cascadia/WindowsTerminal/AppHost.cpp (L1208-L1237)

See the bug?

I'm betting that the app exits before the coroutine gets scheduled. That's a hunch.

North of the ShowWindow call, user32 calls back to our WndProc:

L: 35 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::GetTotalNonClientExclusiveSize
  L: 45 | 100.00%WindowsTerminal.exe!IslandWindow::MessageHandler
    L: 55 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::MessageHandler
      L: 65 | 100.00%WindowsTerminal.exe!BaseWindow_IslandWindow_::WndProc
L: 426 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::OnSize
  L: 526 | 100.00%WindowsTerminal.exe!IslandWindow::OnResize
    L: 626 | 100.00%WindowsTerminal.exe!IslandWindow::MessageHandler
      L: 726 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::MessageHandler
        L: 826 | 100.00%WindowsTerminal.exe!BaseWindow_IslandWindow_::WndProc

Loading dumps.

Originally created by @zadjii-msft on GitHub (May 26, 2023). Two bugs, pretty sure same root cause. I believe this is collectively **21% of the crashes** in 1.18 so far. * MSFT:44725712 "WindowsTerminal.exe!NonClientIslandWindow::OnSize" * MSFT:44754014 "NonClientIslandWindow::GetTotalNonClientExclusiveSize" Both have stacks north of `WindowsTerminal.exe!AppHost::_WindowInitializedHandler$_ResumeCoro$` https://github.com/microsoft/terminal/blob/3c3b1aac02320f49f6887f08e6d6d1d56132b1ef/src/cascadia/WindowsTerminal/AppHost.cpp#L1208-L1237 See the bug? I'm betting that the app exits before the coroutine gets scheduled. That's a hunch. North of the `ShowWindow` call, user32 calls back to our WndProc: ``` L: 35 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::GetTotalNonClientExclusiveSize L: 45 | 100.00%WindowsTerminal.exe!IslandWindow::MessageHandler L: 55 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::MessageHandler L: 65 | 100.00%WindowsTerminal.exe!BaseWindow_IslandWindow_::WndProc ``` ``` L: 426 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::OnSize L: 526 | 100.00%WindowsTerminal.exe!IslandWindow::OnResize L: 626 | 100.00%WindowsTerminal.exe!IslandWindow::MessageHandler L: 726 | 100.00%WindowsTerminal.exe!NonClientIslandWindow::MessageHandler L: 826 | 100.00%WindowsTerminal.exe!BaseWindow_IslandWindow_::WndProc ``` Loading dumps.
claunia added the In-PRNeeds-Tag-FixProduct-TerminalSeverity-Crash labels 2026-01-31 06:59:42 +00:00
Author
Owner

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

hey @lhecker member when you were like

"We should SetWindowLongPtr so that we don't get callbacks on our window message loops anymore"

yea we should probably do that. I'm not sure how to repro this, so this is gonna be one of them hypothetical fixes.

But all of these stacks are north of WindowThread::RundownForExit, where we're pumping remaining callbacks.

  • We close our XAML source,
  • we don't null out the IslandWindow,
  • we pump the remaining messages,
    • while we're pumping, we get the _WindowInitializedHandler coroutine scheduled
    • that calls ShowWindow,
    • that immediately calls back into NCIW / IslandWindow, based off the BaseWindow's WndProc.
      • In the case of GetTotalNonClientExclusiveSize, we try to ask for the _titlebar's height but OOPS NO XAML
      • In the case of OnSize, we call to SetWindowPos(_interopWindowHandle, but OOPS XAML ALREADY CloseWindow'd that HWND

So yea, I think we can definitely just sidestep this entire class of issues by doing a SetWindowLongPtr in IslandWindow::Close

@zadjii-msft commented on GitHub (May 26, 2023): hey @lhecker member when you were like "We should `SetWindowLongPtr` so that we don't get callbacks on our window message loops anymore" yea we should probably do that. I'm not sure how to repro this, so this is gonna be one of them _hypothetical fixes_. But all of these stacks are north of `WindowThread::RundownForExit`, where we're pumping remaining callbacks. * We close our XAML source, * we _don't_ null out the `IslandWindow`, * we pump the remaining messages, * while we're pumping, we get the `_WindowInitializedHandler` coroutine scheduled * that calls `ShowWindow`, * that immediately calls back into NCIW / IslandWindow, based off the `BaseWindow`'s `WndProc`. * In the case of `GetTotalNonClientExclusiveSize`, we try to ask for the `_titlebar`'s height but OOPS NO XAML * In the case of `OnSize`, we call to `SetWindowPos(_interopWindowHandle`, but OOPS XAML ALREADY `CloseWindow`'d that HWND So yea, I think we can definitely just sidestep this entire class of issues by doing a `SetWindowLongPtr` in `IslandWindow::Close`
Author
Owner

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

Oh, wow I had already forgotten about the SetWindowLongPtr approach.

@lhecker commented on GitHub (May 26, 2023): Oh, wow I had already forgotten about the `SetWindowLongPtr` approach.
Author
Owner

@zadjii-msft commented on GitHub (Jun 16, 2023):

Don't see any more of these on 1.18.1462. Huzzah?

@zadjii-msft commented on GitHub (Jun 16, 2023): Don't see any more of these on 1.18.1462. Huzzah?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19989