templating icon indicating copy to clipboard operation
templating copied to clipboard

Grace handling user requested process termination

Open JanKrivanek opened this issue 3 years ago • 1 comments

Background:

When user requests a processing exit (via Ctrl-C or Ctrl-Break), templating engine does not grace shut any of it's async processing and the process terminates with wxit code 0xC000013A (STATUS_CONTROL_C_EXIT)

Improved expected behavior:

When user requests a processing exit, templating engine safely cancels all of it's processing, exits once done and signals the situation with exit code 130 (https://tldp.org/LDP/abs/html/exitcodes.html)

How to achieve this:

We should resort from trying to intercept the singla ourselves (with SetConsoleCtrlHandler) Rather we should use the build in functionality of process termination handling within command-line-api This will require adding CancelOnProcessTermination to command line builder within sdk Ideally we should inject this handling for templating subcommand only - in case other subcommands cancellation logic would not be ready (hence leading to uncancellable process). Alternative might be to improve the CancelOnProcessTermination in command line api to allow optional termination processing timeout, after which expiry the process would exit anyway (probably with Environment.Exit(130)) - then we possibly could register the middleware for all dotnet subcommands - those not ready to grace handle cancellation on termination would keep terminating anyways

JanKrivanek avatar May 31 '22 11:05 JanKrivanek

In other commands we should use the 'sync to async' wrapper: https://github.com/dotnet/sdk/blob/dbf884654f7559433c732267472fffd75db8e33c/src/Cli/dotnet/commands/ParseResultCommandHandler.cs#L8 It should grab the Cancellation token from context and Wait on the Task with that CancellationToken

JanKrivanek avatar May 31 '22 14:05 JanKrivanek