Infinite loop in TerminalWindow::OnDirectKeyEvent #19816

Closed
opened 2026-01-31 06:54:23 +00:00 by claunia · 1 comment
Owner

Originally created by @j4james on GitHub (May 4, 2023).

Windows Terminal version

Commit 97a617a909

Windows build number

10.0.19045.2728

Other Software

No response

Steps to reproduce

  1. Open the Settings page in Windows Terminal.
  2. Click on the button that opens the settings.json file (for me this is associated with Notepad, which might be a factor).
  3. Change some value in the settings.json file and save the changes.
  4. Press Alt+F4 to close the editor, returning the focus back to the Terminal.

Expected Behavior

Focus should be returned to the terminal and not hang.

Actual Behavior

The terminal is frozen, and from the debugger and I can see that it's stuck in an infinite loop in TerminalWindow::OnDirectKeyEvent. Every couple of iterations it finds a focusedObject with a IDirectKeyListener, which calls through to TerminalPage::OnDirectKeyEvent, but the key isn't handled (it appears to be a VK_MENU key), and so the loop doesn't exit. And while it keeps calling focusedElement.Parent() to bubble the event, that doesn't end it either. It eventually gets back to the same focusedObject as before.

I'm not positive that the steps given above will always reproduce the issue, but I get it a lot.

Originally created by @j4james on GitHub (May 4, 2023). ### Windows Terminal version Commit 97a617a909f1dd3664daf3a1764c9a7e8996a1b8 ### Windows build number 10.0.19045.2728 ### Other Software _No response_ ### Steps to reproduce 1. Open the _Settings_ page in Windows Terminal. 2. Click on the button that opens the `settings.json` file (for me this is associated with Notepad, which might be a factor). 3. Change some value in the `settings.json` file and save the changes. 4. Press <kbd>Alt</kbd>+<kbd>F4</kbd> to close the editor, returning the focus back to the Terminal. ### Expected Behavior Focus should be returned to the terminal and not hang. ### Actual Behavior The terminal is frozen, and from the debugger and I can see that it's stuck in an infinite loop in `TerminalWindow::OnDirectKeyEvent`. Every couple of iterations it finds a `focusedObject` with a `IDirectKeyListener`, which calls through to `TerminalPage::OnDirectKeyEvent`, but the key isn't handled (it appears to be a `VK_MENU` key), and so the loop doesn't exit. And while it keeps calling `focusedElement.Parent()` to bubble the event, that doesn't end it either. It eventually gets back to the same `focusedObject` as before. I'm not positive that the steps given above will always reproduce the issue, but I get it a lot.
Author
Owner

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

Thanks for filing this! This is definitely a real issue that I started something for in #15253. We need to loop back on that and get that fixed.

@zadjii-msft commented on GitHub (May 4, 2023): Thanks for filing this! This is definitely a real issue that I started something for in #15253. We need to loop back on that and get that fixed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19816