Skip to content

Console.ForegroundColor deadlocks Console on OSX #34197

@lduchosal

Description

@lduchosal

Description

The console is locked with the following conditions :

Thread dotnet/core#1. Console.WriteLine
Thread dotnet/core#2. Console.ForegroundColor locks and never returns
Thread dotnet/core#3. Console.ReadLine is locked and never returns

Problem on NET Core OSX version 3.1.200. Works on Windows x64.

Expected

Thread dotnet/core#1. Console.WriteLine
Thread dotnet/core#2. Console.ForegroundColor returns
Thread dotnet/core#3. Console.ReadLine returns

Code to reproduce

`

class Program
{
    static void Main(string[] args)
    {

        // remove this line to workaround the bug
        Console.WriteLine(@"Program.Main, try a few times to reproduce the issue");

        var wait1 = new AutoResetEvent(false);
        var wait2 = new AutoResetEvent(false);
        
        Task.Factory.StartNew(() =>
        {
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("never happens");
            Console.ResetColor();
            
            wait1.Set();
        });

        Task.Factory.StartNew(() =>
        {
            var line = Console.ReadLine();
            Console.WriteLine("never happens");
            wait2.Set();
        });

        WaitHandle.WaitAll(new[] {wait1, wait2});
        Console.WriteLine("never happens");

    }
}

`

environnement

SDK .NET Core (reflétant tous les global.json) :
Version: 3.1.200
Commit: c5123d973b

Environnement d'exécution :
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/3.1.200/

Host (useful for support):
Version: 3.1.2
Commit: 916b5cba26

.NET Core SDKs installed:
3.1.200 [/usr/local/share/dotnet/sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Thanks for your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions