Windows Terminal hangs when erasing scrollback #3036

Closed
opened 2026-01-30 23:11:24 +00:00 by claunia · 4 comments
Owner

Originally created by @j4james on GitHub (Jul 31, 2019).

Originally assigned to: @PankajBhojwani on GitHub.

Environment

Windows build number: Version 10.0.18362.175
Windows Terminal version (if applicable): Commit a08666b58e

Steps to reproduce

  1. Start the Windows Terminal (Dev Build).
  2. Open an Ubuntu tab (or whatever Linux shell you have).
  3. Do a bunch of directory listings that really fill up the scrollback buffer (the System32 directory is good for that).
  4. Execute printf "\e[3J" to clear the scrollback buffer.

Expected behavior

The scrollback buffer should be cleared and control returned to the user almost immediately.

Actual behavior

The app essentially stops responding. It will return to normal eventually, but how long that takes depends on the speed of your computer and how full the scrollback was to start with.

This might be a duplicate of one of the other freeze-on-exit bugs (e.g. #1445), since the terminal seems to generate an erase scrollback call whenever you exit. But it only happens when actually typing exit in the shell - closing the tab directly works OK.

From what I've been able to determine, the source of the problem is in the Terminal::EraseInDisplay method. When the eraseType is EraseType::Scrollback, it performs a loop to clear every line of the scrollback:

a08666b58e/src/cascadia/TerminalCore/TerminalApi.cpp (L340-L345)

Note that the eraseIter OutputCellIterator is set to the size of the full area being cleared, but a _buffer->Write call is made with that iterator for every line. Each one of those calls is enough to clear the entire area, so it's essentially performing a huge write operation over and over again. If your scrollback buffer is large, this can take forever.

I think this is probably a regression. I have preview build 0.2.1831.0 installed on this machine too, and that doesn't seem to have the problem.

Originally created by @j4james on GitHub (Jul 31, 2019). Originally assigned to: @PankajBhojwani on GitHub. # Environment Windows build number: Version 10.0.18362.175 Windows Terminal version (if applicable): Commit a08666b58eb65b85ddf94e69892fa3e0a084ba98 # Steps to reproduce 1. Start the Windows Terminal (Dev Build). 2. Open an Ubuntu tab (or whatever Linux shell you have). 3. Do a bunch of directory listings that really fill up the scrollback buffer (the System32 directory is good for that). 4. Execute `printf "\e[3J"` to clear the scrollback buffer. # Expected behavior The scrollback buffer should be cleared and control returned to the user almost immediately. # Actual behavior The app essentially stops responding. It will return to normal eventually, but how long that takes depends on the speed of your computer and how full the scrollback was to start with. This might be a duplicate of one of the other freeze-on-exit bugs (e.g. #1445), since the terminal seems to generate an erase scrollback call whenever you exit. But it only happens when actually typing `exit` in the shell - closing the tab directly works OK. From what I've been able to determine, the source of the problem is in the `Terminal::EraseInDisplay` method. When the eraseType is `EraseType::Scrollback`, it performs a loop to clear every line of the scrollback: https://github.com/microsoft/terminal/blob/a08666b58eb65b85ddf94e69892fa3e0a084ba98/src/cascadia/TerminalCore/TerminalApi.cpp#L340-L345 Note that the _eraseIter_ `OutputCellIterator` is set to the size of the full area being cleared, but a `_buffer->Write` call is made with that iterator for every line. Each one of those calls is enough to clear the entire area, so it's essentially performing a huge write operation over and over again. If your scrollback buffer is large, this can take forever. I think this is probably a regression. I have preview build 0.2.1831.0 installed on this machine too, and that doesn't seem to have the problem.
Author
Owner

@j4james commented on GitHub (Jul 31, 2019):

I don't know why I didn't check this before, but I see now that the Terminal::EraseInDisplay method was only just added in PR #2144, so this can't be a duplicate of any of those older freezing bugs.

@j4james commented on GitHub (Jul 31, 2019): I don't know why I didn't check this before, but I see now that the `Terminal::EraseInDisplay` method was only just added in PR #2144, so this can't be a duplicate of any of those older freezing bugs.
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 31, 2019):

@PankajBhojwani is taking a look at this. Thanks for the quick catch!

@DHowett-MSFT commented on GitHub (Jul 31, 2019): @PankajBhojwani is taking a look at this. Thanks for the quick catch!
Author
Owner

@DHowett-MSFT commented on GitHub (Jul 31, 2019):

This is my bad. I suggested that he make sure that we had enough bytes in the iterator to "fill the screen" under the erroneous assumption that it would take 1*rowLength every time. 😄

@DHowett-MSFT commented on GitHub (Jul 31, 2019): This is my bad. I suggested that he make sure that we had enough bytes in the iterator to "fill the screen" under the erroneous assumption that it would take `1*rowLength` every time. :smile:
Author
Owner

@DHowett-MSFT commented on GitHub (Aug 1, 2019):

Triage 0.3 blocking

@DHowett-MSFT commented on GitHub (Aug 1, 2019): Triage 0.3 blocking
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#3036