WPF terminal control in a tabbed interface deadlocks when rapidly opening new tabs #23638

Open
opened 2026-01-31 08:47:55 +00:00 by claunia · 1 comment
Owner

Originally created by @lhecker on GitHub (Sep 23, 2025).

Discussed in https://github.com/microsoft/terminal/discussions/19371

Originally posted by MamiyaOtaru September 23, 2025
I've made use of the WPF Control and mitchcapper's https://github.com/mitchcapper/EasyWindowsTerminalControl to create a simple tabbed terminal. Been fun reading OSC codes and changing the color or text on tabs etc.

BUT rapidly opening new tabs frequently leads to deadlocks.

The hang seems to be related to HwndTerminal.TerminalSetCursorVisible() and its use of _terminal->LockForWriting()

I can avoid them for the most part by handling and ignoring WM_KILLFOCUS in my main window but that makes setting focus to a new tab or a switched to tab very problematic and probably breaks other stuff.

Working much better is if I comment out
//NativeMethods.TerminalSetCursorVisible(this.terminal, false);
in case NativeMethods.WindowMessage.WM_KILLFOCUS:
in TerminalContainer.cs. With that I do not get the deadlocks. Downside: the cursor does not disappear when focus is lost (doesn't blink though!). That is an acceptable tradeoff for me. It is however annoying having to patch that with every release though rather than just using the latest .nupkg of Microsoft.Terminal.WPF

AFAICT what is happening with rapid presses of the new tab button is a new terminal is created, made visible, and then quickly unfocused when another new terminal in a new tab is created and somewhere in there a couple threads are waiting on a lock.

Anyway not sure if this is bug worthy. I don't think you have terminal.wpf out for general consumption yet and I am using it through a third party and probably abusing it by pressing that new tab button too much. But maybe there's something else I can do about it, or maybe a relatively easy way (for me) to replicate it indicates something can/should be done, dunno!

image
Originally created by @lhecker on GitHub (Sep 23, 2025). ### Discussed in https://github.com/microsoft/terminal/discussions/19371 <div type='discussions-op-text'> <sup>Originally posted by **MamiyaOtaru** September 23, 2025</sup> I've made use of the WPF Control and mitchcapper's https://github.com/mitchcapper/EasyWindowsTerminalControl to create a simple tabbed terminal. Been fun reading OSC codes and changing the color or text on tabs etc. BUT rapidly opening new tabs frequently leads to deadlocks. The hang seems to be related to HwndTerminal.TerminalSetCursorVisible() and its use of _terminal->LockForWriting() I can avoid them for the most part by handling and ignoring WM_KILLFOCUS in my main window but that makes setting focus to a new tab or a switched to tab very problematic and probably breaks other stuff. Working much better is if I comment out //NativeMethods.TerminalSetCursorVisible(this.terminal, false); in case NativeMethods.WindowMessage.WM_KILLFOCUS: in **TerminalContainer.cs**. With that I do not get the deadlocks. Downside: the cursor does not disappear when focus is lost (doesn't blink though!). That is an acceptable tradeoff for me. It is however annoying having to patch that with every release though rather than just using the latest .nupkg of Microsoft.Terminal.WPF AFAICT what is happening with rapid presses of the new tab button is a new terminal is created, made visible, and then quickly unfocused when another new terminal in a new tab is created and somewhere in there a couple threads are waiting on a lock. Anyway not sure if this is bug worthy. I don't think you have terminal.wpf out for general consumption yet and I am using it through a third party and probably abusing it by pressing that new tab button too much. But maybe there's something else I can do about it, or maybe a relatively easy way (for me) to replicate it indicates something can/should be done, dunno! <img width="1192" height="734" alt="image" src="https://github.com/user-attachments/assets/5ead7ff6-c0f8-4fa3-865a-877c69e6a788" /> </div>
claunia added the Issue-BugPriority-3Product-TerminalArea-WPFControl labels 2026-01-31 08:47:55 +00:00
Author
Owner

@lhecker commented on GitHub (Sep 23, 2025):

I suspect that this is due to a race condition. #19330 may fix this, because it rewrites all of the focus/blink code, but I'm not sure if it solves the underlying race condition (= it may show up elsewhere).

@lhecker commented on GitHub (Sep 23, 2025): I suspect that this is due to a race condition. #19330 may fix this, because it rewrites all of the focus/blink code, but I'm not sure if it solves the underlying race condition (= it may show up elsewhere).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#23638