dotnet / dotnet/runtime

Regression on Linux: Console uninitialized on AppDomain.UnhandledException

Open
#128,334 10 comments 2 reactions 1 assignee Claimed by @tmds View on GitHub
area-System.Console needs-further-triage
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

### Description

In this PR https://github.com/dotnet/runtime/pull/111272 dotnet now uninitializes the terminal on AppDomain.UnhandledException.
But user code can process other terminal IO operations within another handler of AppDomain.UnhandledException

### Reproduction Steps

```
Console.WriteLine("Hello, World!");
Console.TreatControlCAsInput = true;

AppDomain.CurrentDomain.UnhandledException += (_, args) =>
{
Console.WriteLine("Unhandled exception. Press CTRL+C see the exception");

if (Console.ReadKey(true) is { Modifiers: ConsoleModifiers.Control, Key: ConsoleKey.C })
Console.WriteLine(args.ExceptionObject.ToString());

Console.WriteLine("Bye..");
};

throw new Exception("Dummy exception");
```

### Expected behavior

Once the suggestion to press "CTRL+C" is shown and we pressed "CTRL+C" the application must recognize it because previously we has set `Console.TreatControlCAsInput = true;` and print the exception text.

### Actual behavior

Application just exists without executing the rest of the handler

### Regression?

It worked before https://github.com/dotnet/runtime/pull/111272

### Known Workarounds

User handler can be subscribed before any initialization of pal_console.c happened.
In this case unitialization would happen only after allowing previous handlers to be executed in still initialized environment.
The issue with this workaround is a difficulty to control when console gets initialized.

### Configuration

dotnet 10.0.100
x64, Linux

### Other information

Relevant to https://github.com/dotnet/runtime/issues/110502

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.