System.CommandLine v2.0.0-beta1.21216.1
This project demonstrates a deadlock condition in the System.CommandLine library.
Based on my debugging the deadlock happens when a command handler is returning
and the Ctrl+C handler is trying to detach the event handler on the
Console.CancelKeyPress
event handler. It appears to lock the thread when trying
to detach the handler. The issue seems to be dependent on an assembly being loaded
via Assembly.LoadFile
.
> cd .\bin
> .\DeadlockSample.exe
Once prompted press Ctrl+C
to trigger the deadlock:
> .\DeadlockSample.exe
Press Ctrl+C to exit...
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at DeadlockSample.MyApp.<Run>d__0.MoveNext() in C:\dev\tmp\DeadlockSample\DeadlockSample.MyApp\MyApp.cs:line 15
The app does not exit as expected.
Stack traces of the deadlocked state: