Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Improve Ctrl-C experience for dotnet run. - #10544

Merged
peterhuene merged 1 commit into
dotnet:masterfrom
peterhuene:signal-handling
Jan 7, 2019
Merged

peterhuene merged 1 commit into
dotnet:masterfrom
peterhuene:signal-handling

Conversation

@peterhuene

Copy link
Copy Markdown

This commit improves the handling of the SIGINT signal from dotnet run.

The current behavior of dotnet run is to use the default handler for the
SIGINT signal. This results in the termination of the dotnet run process
with an exit status of 130 on POSIX systems and 0xC000013A on Windows. This
prevents a child process to gracefully handle SIGINT by returning a zero exit
code or from ignoring the signal entirely and letting the process appear to
continue to run.

Additionally, the child process of dotnet run may still be writing to stdout
during the handling of SIGINT. Because dotnet run may terminate before the
child process does, a waiting parent of dotnet run, such as a shell, may
proceed to print out a new prompt to the user while the child continues to
write to stdout. This results in inconsistent and interleaved output in a
terminal and can be a source of confusion to users.

This commit changes dotnet to always ignore SIGINT when spawning a child
process. This allows the child process to handle the signal and decide what to
do with it. As a result, the UX from when the user program is run directly or
via dotnet run is the same regarding SIGINT.

Fixes #812.

@peterhuene
peterhuene requested a review from a team January 5, 2019 00:43
@peterhuene peterhuene added this to the 3.0 Preview2 milestone Jan 5, 2019
@peterhuene

Copy link
Copy Markdown
Author

Note: there is not a Windows test for this for the same reason corefx doesn't test CancelKeyPress on Windows (see this comment).

This commit improves the handling of the SIGINT signal from `dotnet run`.

The current behavior of `dotnet run` is to use the default handler for the
SIGINT signal.  This results in the termination of the `dotnet run` process
with an exit status of 130 on POSIX systems and 0xC000013A on Windows.  This
prevents a child process to gracefully handle SIGINT by returning a zero exit
code or from ignoring the signal entirely and letting the process appear to
continue to run.

Additionally, the child process of `dotnet run` may still be writing to stdout
during the handling of SIGINT.  Because `dotnet run` may terminate before the
child process does, a waiting parent of `dotnet run`, such as a shell, may
proceed to print out a new prompt to the user while the child continues to
write to stdout.  This results in inconsistent and interleaved output in a
terminal and can be a source of confusion to users.

This commit changes `dotnet` to always ignore SIGINT when spawning a child
process.  This allows the child process to handle the signal and decide what to
do with it.  As a result, the UX from when the user program is run directly and
run via `dotnet run` is the same regarding SIGINT.

Fixes #812.
@peterhuene
peterhuene merged commit 69abb9c into dotnet:master Jan 7, 2019
@peterhuene
peterhuene deleted the signal-handling branch January 7, 2019 20:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants