Skip to content

Grace handling user requested process termination #4799

Closed as not planned
Closed as not planned

Description

@JanKrivanek

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

Activity

  1. JanKrivanek commented on May 31, 2022

    @JanKrivanek
    MemberAuthor

    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

  2. self-assigned this
    on Jun 6, 2022
  3. added
    triaged
    on Jun 6, 2022
  4. added this to the June 2022 milestone on Jun 6, 2022
  5. added
    Priority:3
    area: CLI
    on May 16, 2023
  6. added
    triage:close-wont-fix
    on May 7, 2026
  7. marcpopMSFT commented on May 27, 2026

    @marcpopMSFT
    Member

    This issue is being closed as won't fix. It has been open for an extended period without maintainer activity or community demand, and is unlikely to be addressed.

    The dotnet/templating repository has been consolidated into dotnet/sdk. If this issue is still important to you, please open a new issue in dotnet/sdk with updated context so the team can re-evaluate.

    Triage details

    Summary: Request to gracefully handle Ctrl-C process termination in the template engine CLI with proper exit codes

    Reasoning: This issue is nearly 4 years old with 0 upvotes and only 1 comment (from the author). Last activity was over 3 years ago (May 2023). It describes improving Ctrl-C handling in the template engine CLI, which requires cross-repo changes in dotnet/sdk and command-line-api. The lack of community interest and long staleness suggest this is unlikely to be prioritized. The consolidation into SDK could make this easier to address but doesn't inherently resolve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Priority:3area: CLItriage:close-wont-fixtriaged

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions