Resizing a Terminal with retro terminal effects hangs the Terminal #7243

Closed
opened 2026-01-31 00:58:51 +00:00 by claunia · 5 comments
Owner

Originally created by @zadjii-msft on GitHub (Apr 1, 2020).

Originally assigned to: @DHowett-MSFT on GitHub.

This is on the selfhost 0.11.912.0 release, but also repro'd on the last 0.11 preview. Unsure if it repros on earlier builds also.

Add the following to a profile:

"experimental.retroTerminalEffect": true

Then open a tab with that profile and try resizing the Terminal.

Expected

The Terminal should not hang.

Actual

It hangs 😢

Looks like we're waiting for the read lock at the top of TermControl::RenderEngineSwapChainChanged on the RenderThread. This is higher on the stack than Renderer::_PaintFrameForEngine, which I believe has a write lock. But it's the same thread, so we should be fine, right?

Oh no the main thread also is waiting on the write lock 😲

03 TerminalControl!std::unique_lock<std::shared_mutex>::{ctor}+0x8 
04 TerminalControl!Microsoft::Terminal::Core::Terminal::LockForWriting+0x14
05 TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl::_SwapChainSizeChanged+0x37
06 TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControlT<winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl>::Connect::__l10::<lambda_87fbcfa1739d624dde571db8710dac26>::operator()+0x77 

Wait no, that's fine. The main thread doesn't have the lock, it's just waiting for it. That's fine. I think the problem is the render thread can't seem to re-enter the lock

because it's a shared_mutex not a recursive_mutex

Originally created by @zadjii-msft on GitHub (Apr 1, 2020). Originally assigned to: @DHowett-MSFT on GitHub. This is on the selfhost 0.11.912.0 release, but also repro'd on the last 0.11 preview. Unsure if it repros on earlier builds also. Add the following to a profile: ```json "experimental.retroTerminalEffect": true ``` Then open a tab with that profile and try resizing the Terminal. ### Expected The Terminal should not hang. ### Actual It hangs 😢 Looks like we're waiting for the read lock at the top of `TermControl::RenderEngineSwapChainChanged` on the `RenderThread`. This is higher on the stack than `Renderer::_PaintFrameForEngine`, which I believe has a write lock. But it's the same thread, so we should be fine, right? Oh no the main thread also is waiting on the write lock 😲 ``` 03 TerminalControl!std::unique_lock<std::shared_mutex>::{ctor}+0x8 04 TerminalControl!Microsoft::Terminal::Core::Terminal::LockForWriting+0x14 05 TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl::_SwapChainSizeChanged+0x37 06 TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControlT<winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl>::Connect::__l10::<lambda_87fbcfa1739d624dde571db8710dac26>::operator()+0x77 ``` Wait no, that's fine. The main thread doesn't _have_ the lock, it's just waiting for it. That's fine. I think the problem is the render thread can't seem to re-enter the lock because it's a `shared_mutex` not a [`recursive_mutex`](https://en.cppreference.com/w/cpp/thread/recursive_mutex)
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 1, 2020):

I accept that this is probably my fault: call stack looks like it's in LockForWriting 😉

@DHowett-MSFT commented on GitHub (Apr 1, 2020): I accept that this is _probably_ my fault: call stack looks like it's in `LockForWriting` :wink:
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 1, 2020):

Oh, you .. already .. did that. Ugh, sorry.

@DHowett-MSFT commented on GitHub (Apr 1, 2020): Oh, you .. already .. did that. Ugh, sorry.
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 1, 2020):

I'm actually seeing a second thread contending the lock also handling a swap chain change.

02 (Inline Function) --------`-------- TerminalControl!std::shared_mutex::lock_shared+0x5 [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\include\shared_mutex @ 55] 
03 (Inline Function) --------`-------- TerminalControl!std::shared_lock<std::shared_mutex>::{ctor}+0x5 [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\include\shared_mutex @ 241] 
04 (Inline Function) --------`-------- TerminalControl!Microsoft::Terminal::Core::Terminal::LockForReading+0x17 [E:\BA\193\s\src\cascadia\TerminalCore\Terminal.cpp @ 542] 
05 00000037`4cfff580 00007ffc`cc0931f5 TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl::RenderEngineSwapChainChanged$_ResumeCoro$2+0xb3 [E:\BA\193\s\src\cascadia\TerminalControl\TermControl.cpp @ 489] 
06 00000037`4cfff690 00007ffc`cc0a1a5b TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl::RenderEngineSwapChainChanged+0x45 [E:\BA\193\s\src\cascadia\TerminalControl\TermControl.cpp @ 506] 
@DHowett-MSFT commented on GitHub (Apr 1, 2020): I'm actually seeing a second thread contending the lock _also_ handling a swap chain change. ``` 02 (Inline Function) --------`-------- TerminalControl!std::shared_mutex::lock_shared+0x5 [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\include\shared_mutex @ 55] 03 (Inline Function) --------`-------- TerminalControl!std::shared_lock<std::shared_mutex>::{ctor}+0x5 [C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.24.28314\include\shared_mutex @ 241] 04 (Inline Function) --------`-------- TerminalControl!Microsoft::Terminal::Core::Terminal::LockForReading+0x17 [E:\BA\193\s\src\cascadia\TerminalCore\Terminal.cpp @ 542] 05 00000037`4cfff580 00007ffc`cc0931f5 TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl::RenderEngineSwapChainChanged$_ResumeCoro$2+0xb3 [E:\BA\193\s\src\cascadia\TerminalControl\TermControl.cpp @ 489] 06 00000037`4cfff690 00007ffc`cc0a1a5b TerminalControl!winrt::Microsoft::Terminal::TerminalControl::implementation::TermControl::RenderEngineSwapChainChanged+0x45 [E:\BA\193\s\src\cascadia\TerminalControl\TermControl.cpp @ 506] ```
Author
Owner

@DHowett-MSFT commented on GitHub (Apr 1, 2020):

UGH YOU ALREADY DID THAT PART TOO okay i'm stopping

@DHowett-MSFT commented on GitHub (Apr 1, 2020): UGH YOU ALREADY DID THAT PART TOO okay i'm stopping
Author
Owner

@ghost commented on GitHub (Apr 22, 2020):

:tada:This issue was addressed in #5225, which has now been successfully released as Windows Terminal Preview v0.11.1121.0.🎉

Handy links:

@ghost commented on GitHub (Apr 22, 2020): :tada:This issue was addressed in #5225, which has now been successfully released as `Windows Terminal Preview v0.11.1121.0`.:tada: Handy links: * [Release Notes](https://github.com/microsoft/terminal/releases/tag/v0.11.1121.0) * [Store Download](https://www.microsoft.com/store/apps/9n0dx20hk701?cid=storebadge&ocid=badge)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#7243