terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Startup hang: snap-to-grid loop spins forever in WM_GETMINMAXINFO while persisted panes are still being created

Open virzak opened this issue 1 month ago • 2 comments

Windows Terminal version

1.25.2733.0 (also the portable zip)

Windows build number

10.0.26300.9711

Other Software

TrueCrypt volume holding the tabs' starting directories.

Steps to reproduce

  1. "firstWindowPreference": "persistedLayout", snapToGridOnResize at its default (on).
  2. Use the attached state.json (4 windows, 44 tabs, 41 splits, all cmd.exe), with startingDirectory pointed at a folder on a slow volume. Mine is an encrypted TrueCrypt drive.
  3. Launch Terminal a few times; it is a race. 3 of 5 launches hung for me, none with the same layout on C:.

Expected Behavior

The layout restores.

Actual Behavior

The UI thread spins at 100% CPU indefinitely after 6-7 panes have started, and later wt.exe launches are handed to the hung process. Stack of the spinning thread:

TerminalApp!Pane::_CalcSnappedChildrenSizes+0x6b
TerminalApp!Pane::_CalcSnappedDimension+0x114e21
TerminalApp!Pane::CalcSnappedDimension+0x1c
TerminalApp!winrt::TerminalApp::implementation::TerminalPage::CalcSnappedDimension+0x98
WindowsTerminal!IslandWindow::_OnGetMinMaxInfo+0xa5
WindowsTerminal!IslandWindow::MessageHandler+0x4b2
...
win32u!NtUserShowWindow+0x14
WindowsTerminal!AppHost::_WindowInitializedHandler$_ResumeCoro$1+0x217

Likely cause: a control that has not been initialized yet reports a cell width of 0 (_actualFont starts at { 0, DEFAULT_FONT_SIZE }), so _AdvanceSnappedDimension adds 0 and the while (sizeTree.size < fullSize) loop never ends. Unchanged on main. Guarding against a zero grid unit should fix it.

Workaround: "snapToGridOnResize": false (0 of 5 hangs vs 2 of 5 with it on).

Probably the same hang as #18610. My #20765 blamed persisted buffers; that was wrong, this is the cause.

virzak avatar Oct 26 '26 19:10 virzak

The stack trace confirms the re-entrant WM_GETMINMAXINFO call is hitting Pane::_CalcSnappedChildrenSizes while _actualFont is still uninitialized, leading to a division-by-zero or infinite loop in the dimension calculation. Since the font initialization relies on the rendering engine which is likely stalled by the slow TrueCrypt drive, we should add a guard clause to _CalcSnappedChildrenSizes to return early if the font dimensions are zero or the control is not yet fully realized. Alternatively, is there a way to defer the WM_GETMINMAXINFO request until the TerminalPage signals that the layout state is stable?

rorieaniston26 avatar Oct 27 '26 01:10 rorieaniston26

I reproduced the startup hang from this issue on Windows Terminal Preview 1.26.3133.0 x64 (MSIX) with Windows build 10.0.26300.10075.

Reproduction on this machine

  1. Start with firstWindowPreference set to persistedLayoutAndContent and snapToGridOnResize omitted (the default is true). The saved state contains four maximized windows, with ten panes across six split actions.
  2. Launch Windows Terminal Preview from Start with that saved state. The expected result is that the windows and panes reappear. No window becomes visible, including after subsequent launch attempts.

Evidence

  • App activation succeeded. AppModel-Runtime event 201 and TWinUI event 1621 recorded the launch. The original WindowsTerminal.exe process remained alive for at least 25 minutes, with one thread consuming about one logical CPU core. No matching application crash event was found in the observed time window.
  • A full user-mode dump captured during the hang shows this stack on the hot thread, resolved using Microsoft symbols. The selected frames are listed from the current frame toward its callers.
ntdll!RtlAllocateHeap+0x109
TerminalApp!Pane::_CalcSnappedChildrenSizes+0x6b
TerminalApp!Pane::_CalcSnappedDimension+0x10d70b
TerminalApp!Pane::CalcSnappedDimension+0x1c
TerminalApp!winrt::TerminalApp::implementation::TerminalPage::CalcSnappedDimension+0xbc
WindowsTerminal!IslandWindow::_OnGetMinMaxInfo+0xa5
WindowsTerminal!IslandWindow::MessageHandler+0x30a
win32u!NtUserShowWindow+0x14
WindowsTerminal!AppHost::_WindowInitializedHandler$_ResumeCoro$1+0x217

The full dump is available if a maintainer can provide a private transfer channel. The workaround to verify on the affected installation is "snapToGridOnResize": false.

greenhat616 avatar Nov 21 '26 19:11 greenhat616