Open clguiman opened 1 year ago
Tagging subscribers to this area: @dotnet/area-system-console See info in area-owners.md if you want to be subscribed.
Author: | clguiman |
---|---|
Assignees: | - |
Labels: | `area-System.Console` |
Milestone: | - |
Is this a regression?
The issue doesn't reproduce always so I didn't spend time trying it on net5.
Description
The
Console.OutputEncoding
setter takes a lock ons_syncObject
then callsFlush()
on the s_out and s_error streams. Those streams areSyncTextWriter
objects which have theMethodImpl(MethodImplOptions.Synchronized)
attribute set on their methods. If another thread flushes the console output (e.g.ConsoleLoggerProcessor.ProcessLogQueue
) the locks will be taken in the reverse order:SyncTextWriter.Flush
, that ends up inConsole.Out.EnsureInitialized()
which takes thes_syncObject
lock.Reproduction Steps
I managed to sometimes repro the issue on Linux (WSL) with .net 6.0.14. Here are the deadlocked threads:
Thread 0x121
Thread 0x12F
Expected behavior
The process shouldn't deadlock when setting the output encoding.
Actual behavior
The process deadlocks.
Regression?
No response
Known Workarounds
No response
Configuration
x64 .NET 6.0.14, Ubuntu WSL
Other information
No response