microsoft / terminal

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

Crashes to desktop after setting the console buffer size and writing enough output to scroll #16319

Closed jnm2 closed 11 months ago

jnm2 commented 11 months ago

Windows Terminal version

1.18.2822.0

Windows build number

10.0.22631.2428

Other Software

No response

Steps to reproduce

Compile and run the following .NET program. Reproed on both .NET Core/6 and .NET Framework, as expected.

using System;

public static class Program
{
    public static void Main()
    {
        Console.BufferHeight = 500;

        for (var i = 1; i < 100; i++)
        {
            Console.WriteLine(i.ToString());
        }
    }
}
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net48</TargetFramework>
  </PropertyGroup>

</Project>

Expected Behavior

No crash

Actual Behavior

Crashes to desktop, and the .NET process subsequently crashes on Console.WriteLine with System.IO.IOException: 'No process is on the other end of the pipe.' (.NET 8 doesn't crash on WriteLine, but WindowsTerminal.exe still crashes to desktop.)

When I attach a debugger to WindowsTerminal.exe and run the app, this is the exception:

Exception thrown at 0x00007FFEE7574FFC in WindowsTerminal.exe: Microsoft C++ exception: 1MONZA::DdiThreadingContext<MONZA::AdapterTraits_Gen12LP>::msg_end1 at memory location 0x0000007F32BFFC00.

KernelBase.dll!00007ffee7574ffc()
igd10um64xe.dll!00007ffec24c2830()
igd10um64xe.dll!00007ffec29a1d9c()
igd10um64xe.dll!00007ffec23a3aff()
igd10um64xe.dll!00007ffec2498b26()
igd10um64xe.dll!00007ffec24d3d6a()
kernel32.dll!00007ffee7ef257d()
ntdll.dll!00007ffee9f2aa78()
jnm2 commented 11 months ago

This may be a duplicate of #16212. Looks like the common element is setting .NET's Console.BufferHeight, which is a platform call to https://learn.microsoft.com/en-us/windows/console/setconsolescreenbuffersize.

jnm2 commented 11 months ago

More info: if you resize the Windows Terminal window after the buffer size is changed, it will not proceed to crash once the output starts scrolling the window.

237dmitry commented 11 months ago

There are no crashes in 1.19.3172.01 Tried it in two ways:

$code = @"
  using System;

  public static class Program
  {
      public static void Main()
      {
          Console.BufferHeight = 500;

          for (var i = 1; i < 100; i++)
          {
              Console.WriteLine(i.ToString());
          }
      }
  }
  "@
Add-Type -TypeDefinition $code
[Program]::Main()
[console]::BufferHeight = 500
for ($i = 1; $i -lt 100; $i++) { [console]::WriteLine($i.ToString()) }
jnm2 commented 11 months ago

Cool. Those both repros worked to cause the crash in the older version, I just double-checked. Any idea what commit fixed this?

zadjii-msft commented 11 months ago

Yea we're gonna mark this as /dup #16199. Thanks for the neat, minimal repros!

microsoft-github-policy-service[bot] commented 11 months ago

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!