Install a top-level SIGINT/SIGTERM handler so defers run on ctrl+c#13451
Closed
c-tonneslan wants to merge 1 commit into
Closed
Install a top-level SIGINT/SIGTERM handler so defers run on ctrl+c#13451c-tonneslan wants to merge 1 commit into
c-tonneslan wants to merge 1 commit into
Conversation
Closes cli#13401. Without a top-level signal handler, Go's default behavior calls os.Exit() on the first ctrl+c, which skips the deferred telemetryService.Flush() and any cleanup defers in long-running commands like 'gh cs ports forward', 'gh cs ssh', and 'gh run download'. Installing one via signal.Notify suppresses the auto-exit so the in-flight command can return normally and the deferred work runs. A second signal still hard-exits in case something is genuinely stuck. Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
|
Thanks for your pull request! While it doesn't meet all of our standard requirements, it appears to be a small, focused contribution and has been routed to the team for review. Note: We still encourage linking to an issue with the |
Member
|
Closing due to contribution guidelines (no help wanted label) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #13401.
Without a top-level handler, Go's default behavior calls
os.Exit()on the first ctrl+c and skips deferred work:telemetryService.Flush()fromMain, the connection-cleanup defers in long-running codespace commands (gh cs ports forward,gh cs ssh,gh cs logs), and the temp-file removal ingh run download.Installing the handler via
signal.Notifysuppresses Go's auto-exit. The in-flight command returns normally (pagers handle ctrl+c themselves and just close stdin),Mainreturns, and the deferred work runs. A second signal hard-exits in case something is genuinely stuck.