microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
95.7k stars 8.33k forks source link

Crash when exiting a tab with the debug tap #17432

Open j4james opened 5 months ago

j4james commented 5 months ago

Windows Terminal version

Commit c52ba7dec6386e11befb62e81e4c0c970a9c5e3e

Windows build number

10.0.19045.4412

Other Software

No response

Steps to reproduce

I've had this crash quite frequently in the preview build (I think possibly since v1.21), but I couldn't easily reproduce it. However, I've just discovered I can reproduce it consistently when running Windows Terminal from within the debugger with the following steps:

  1. Start Windows Terminal.
  2. Open a second tab with the debug tap.
  3. Type exit to close the second tab.

In both tabs I'm using a WSL bash shell, but I don't think that's relevant. The key thing is typing exit to close the tab rather than clicking on the close button.

Expected Behavior

The tab should close without crashing the terminal.

Actual Behavior

The terminal crashes with an exception in the Pane::_CloseChild method:

Unhandled exception thrown: read access violation.
this->_content.**m_ptr** was nullptr.

On this line: https://github.com/microsoft/terminal/blob/a7e2b46e2070d3d493fb05b1ae358c7f7135ab49/src/cascadia/TerminalApp/Pane.cpp#L1433

And with the following stack trace:

>   TerminalApp.dll!Pane::_CloseChild(const bool closeFirst) Line 1433  C++
    TerminalApp.dll!winrt::impl::delegate<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>,`Pane::_CloseChildRoutine'::`2'::<lambda_1>>::Invoke(void * sender, void * args) Line 883  C++
    [External Code] 
    WindowsTerminal.exe!WindowEmperor::_createNewWindowThread::__l2::<lambda_1>::operator()() Line 222  C++
    [External Code] 

When I've had this crash in the preview build (assuming it was the same thing), it was usually when I was attempting to compile Windows Terminal and my system was low on memory. At the time I thought the lack of memory might have been a factor, but I suspect now that it might be a timing issue, and the low memory was just slowing the system enough for it to trigger the problem. Either way I'm hoping the trace above is enough for someone to figure out the cause.

I had also initially thought this might be the same bug as #17305, but my dev build has both PR #17333 and PR #17358 applied, so it can't be that.

github-actions[bot] commented 5 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

j4james commented 5 months ago

Git bisect suggests this broke in commit ce0f8d6db2aef67ecefaad54a8c92f62291f6361 (PR #17358). But that means the crashes I've been getting in the preview build are something else. Unless perhaps this commit isn't the real source of the bug, but just made it more likely to be triggered?

PankajBhojwani commented 4 months ago

This should be fixed by #17450! Could you just double-check that?

j4james commented 4 months ago

Yes, I can confirm that has fixed it. Thank you!

j4james commented 2 months ago

I'm reopening because this issue has returned. It was fixed by PR #17450, but that was reverted in PR #17750, and now it's crashing again. Exact same steps to reproduce as above, and the stack trace is similar:

>   [Inline Frame] TerminalApp.dll!winrt::impl::consume_TerminalApp_IPaneContent<winrt::TerminalApp::IPaneContent>::GetRoot() Line 662  C++
    TerminalApp.dll!Pane::_CloseChild(const bool closeFirst) Line 1433  C++
    [Inline Frame] TerminalApp.dll!Pane::_CloseChildRoutine::__l2::<lambda_1>::operator()(const winrt::Windows::Foundation::IInspectable &) Line 1687   C++
    TerminalApp.dll!winrt::impl::delegate<winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>,`Pane::_CloseChildRoutine'::`2'::<lambda_1>>::Invoke(void * sender, void * args) Line 883  C++
    [External Code] 
    WindowsTerminal.exe!WindowThread::_messagePump() Line 185   C++
    WindowsTerminal.exe!WindowEmperor::_createNewWindowThread::__l2::<lambda_1>::operator()() Line 228  C++
    [External Code] 

Commit 7b39d24913ec9a6b9fd7026bfd47dc4c7363ccdf was good. Commit 056af839940495989409d69e72e89311b1a7f209 crashes.