Minimal reproduction project for a
System.CommandLinetermination handling issue.
This repo demonstrates a bug introduced in System.CommandLine v2.0.0-beta7.25380.108. The last commit without this issue was 7bb08a6.
-
In commit
3132acb,CommandLineConfigurationwas renamed toInvocationConfiguration. -
During that change, the default value for
ProcessTerminationTimeoutwas dropped. -
Without a default, the following line is skipped in
InvocationPipeline:await terminationHandler.Start(processTerminationTimeout, cancellationToken);
-
This causes the subsequent call to
Task.WhenAny(...)to be skipped. As a result OperationCanceledException may not be propogated to the program consuming System.CommandLine.
-
Clone the repo.
-
Build with the .NET SDK 9.0+:
dotnet build ./src/Culbertson
-
Run the app
dotnet run --project ./src/Culbertson
-
Press Ctrl+C.
The app should,
- Catch the OperationCanceledException
- Print cleanup messages
- Exit with code 42.
The app exits, but does not handle the OperationCanceledException. This flaw jeopardizes potential cleanup routines for consumers.