Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows terminal hangs after running ripgrep in a loop #1360

Closed
Treit opened this issue Jun 21, 2019 · 9 comments · Fixed by #2924 or #4150
Closed

Windows terminal hangs after running ripgrep in a loop #1360

Treit opened this issue Jun 21, 2019 · 9 comments · Fixed by #2924 or #4150
Assignees
Labels
Area-Quality Stability, Performance, Etc. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. Severity-Crash Crashes are real bad news.
Milestone

Comments

@Treit
Copy link

Treit commented Jun 21, 2019

Environment

Windows version 1903 OS build 18899.1000
Windows Terminal (Preview) version 0.2.1703.0

Any other software?
ripgrep 11.0.0

Steps to reproduce

Install ripgrep
Open wt (Windows Terminal), running PowerShell.
Run the following from the root of a large drive
while ($true) { rg -i "foo" }

Expected behavior

The terminal continually runs ripgrep against all files on the drive

Actual behavior

The terminal eventually hangs and is completely unresponsive.

The call stack for the main thread when the window hangs is attached.

HungTerminal1.callstack.txt

A minidump of the hung process is available here:
HungWindowsTerminal

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Jun 21, 2019
@DHowett-MSFT DHowett-MSFT added Product-Terminal The new Windows Terminal. Severity-Crash Crashes are real bad news. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Jun 24, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Jun 24, 2019
@miniksa
Copy link
Member

miniksa commented Sep 11, 2019

The callstack and dump given appears to be in a state of appropriate locks with output being written to the buffer at the time of the dump/stack break.

I'm trying to repro this locally to see if I can find something a bit more obvious.

@Treit
Copy link
Author

Treit commented Sep 12, 2019

The callstack and dump given appears to be in a state of appropriate locks with output being written to the buffer at the time of the dump/stack break.

I'm trying to repro this locally to see if I can find something a bit more obvious.

@miniksa I was able to reproduce it just now on my primary machine so if there is anything I can do to help debug it please let me know.

@Treit
Copy link
Author

Treit commented Sep 20, 2019

@miniksa Just adding some of the details I sent in email here for reference.

The issue I am hitting appears to be an infinite loop in:

void Terminal::_WriteBuffer(const std::wstring_view& stringView)

This is in Terminal.cpp, line 326

On line 372 we have the following code:

i += cellDistance - 1;

I can see in the debugger when this hang reproduces that cellDistance has become 0. Thus, this becomes a decrement instead of an increment.

So, the variable is decremented by one on line 372 and is then incremented by one at the start of the next loop iteration. When it comes back to line 372, i is decremented again, and this process repeats forever.

Further investigation will be needed to determine how cellDistance can become zero and trigger this infinite loop.

@Treit
Copy link
Author

Treit commented Sep 23, 2019

I have found an easier way to reproduce this issue, by running the following trivial C# program:

namespace TerminalStress
{
    using System;
    using System.Text;

    class Program
    {
        static void Main(string[] args)
        {
            Random r = new Random();

            Console.OutputEncoding = Encoding.UTF8;

            while (true)
            {
                char c = (char)r.Next(0xD100, 0xFA95);

                Console.Write(c);
            }
        }
    }
}

@miniksa
Copy link
Member

miniksa commented Sep 26, 2019

Two issues here:

  1. When something inside Terminal::_WriteBuffer, the function that sorely needs to be rewritten in the Boogaloo Bug Implement stream writing mechanism on buffer (a.k.a. WriteCharsLegacy2ElectricBoogaloo) #780, gets the cursor into an X position that falls outside the bounds of the buffer (Cursor X = 120, but the buffer is only valid 0-119), then the TextBuffer::Write methods will refuse to write because they're checking that the cursor is in bounds before attempting to write. This results in a cell-advance count of 0 reported to _WriteBuffer. It doesn't compensate for this in any appreciable manner. It also never realizes that proposedCursorPosition is outside the bounds of the buffer to correct itself down a line (X=0; Y++). Compensating for a 0 cell distance advance, a proposedCursorPosition.X past the buffer end, or both does resolve this issue.

  2. However, something in Write is permitting a cell distance that when advanced by the caller results in a position outside the buffer. That's not correct. That's a character bisect (where we only end up drawing the left half of a wide character). I haven't totally narrowed this one down yet, but I'm looking into it next as it's important to fix this too.

All of this really comes down to.... #780 needs to get done. It would head off this entire class of issue. I'll patch up Terminal::_WriteBuffer now and #780 is booked for November.

@ghost ghost added the In-PR This issue has a related PR label Sep 26, 2019
@ghost ghost closed this as completed in #2924 Oct 1, 2019
ghost pushed a commit that referenced this issue Oct 1, 2019
* Patch fix for #1360 until WriteStream (#780) can be implemented.

* Add a test that hangs in the broken state and passes in the success stat. Writes a bisecting character to the right most cell in the window.

* Code format! *shakes fist at sky*

* Update src/cascadia/TerminalCore/Terminal.cpp
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Oct 1, 2019
DHowett-MSFT pushed a commit that referenced this issue Oct 15, 2019
DHowett-MSFT pushed a commit that referenced this issue Oct 16, 2019
@DHowett-MSFT
Copy link
Contributor

Reopening: the cure was worse than the disease, so we may well just have to wait for #780 to land here. Sorry!

@DHowett-MSFT DHowett-MSFT reopened this Oct 16, 2019
@miniksa miniksa removed the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Oct 18, 2019
@miniksa miniksa modified the milestones: Terminal-1910, Terminal-1911 Oct 18, 2019
@ghost
Copy link

ghost commented Oct 23, 2019

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

Handy links:

@ghost ghost added the In-PR This issue has a related PR label Jan 8, 2020
@ghost ghost closed this as completed in #4150 Jan 15, 2020
ghost pushed a commit that referenced this issue Jan 15, 2020
## Summary of the Pull Request

See [my code comment](#4150 (comment)) below for technical details of the issue that caused #4145.

## PR Checklist
* [x] Closes #1360, Closes #4145.
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Requires documentation to be updated
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

## Detailed Description of the Pull Request / Additional comments

TBH I kinda hope this project could migrate to an internal use of UTF-8 in the future. 😶

## Validation Steps Performed

Followed the "Steps to reproduce" in #4145 and ensured the "Expected behavior" happens.
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. and removed In-PR This issue has a related PR labels Jan 15, 2020
DHowett-MSFT pushed a commit that referenced this issue Jan 24, 2020
## Summary of the Pull Request

See [my code comment](#4150 (comment)) below for technical details of the issue that caused #4145.

## PR Checklist
* [x] Closes #1360, Closes #4145.
* [x] CLA signed. If not, go over [here](https://cla.opensource.microsoft.com/microsoft/Terminal) and sign the CLA
* [ ] Tests added/passed
* [ ] Requires documentation to be updated
* [ ] I've discussed this with core contributors already. If not checked, I'm ready to accept this work might be rejected in favor of a different grand plan. Issue number where discussion took place: #xxx

## Detailed Description of the Pull Request / Additional comments

TBH I kinda hope this project could migrate to an internal use of UTF-8 in the future. 😶

## Validation Steps Performed

Followed the "Steps to reproduce" in #4145 and ensured the "Expected behavior" happens.

(cherry picked from commit 3e6b4b5)
@ghost
Copy link

ghost commented Jan 27, 2020

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

Handy links:

@ghost
Copy link

ghost commented Feb 13, 2020

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

Handy links:

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Quality Stability, Performance, Etc. Area-TerminalControl Issues pertaining to the terminal control (input, selection, keybindings, mouse interaction, etc.) Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. Severity-Crash Crashes are real bad news.
Projects
None yet
6 participants