Skip to content

Install a top-level SIGINT/SIGTERM handler so defers run on ctrl+c#13451

Closed
c-tonneslan wants to merge 1 commit into
cli:trunkfrom
c-tonneslan:fix/install-signal-handler-for-defers
Closed

Install a top-level SIGINT/SIGTERM handler so defers run on ctrl+c#13451
c-tonneslan wants to merge 1 commit into
cli:trunkfrom
c-tonneslan:fix/install-signal-handler-for-defers

Conversation

@c-tonneslan
Copy link
Copy Markdown
Contributor

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() from Main, the connection-cleanup defers in long-running codespace commands (gh cs ports forward, gh cs ssh, gh cs logs), and the temp-file removal in gh run download.

Installing the handler via signal.Notify suppresses Go's auto-exit. The in-flight command returns normally (pagers handle ctrl+c themselves and just close stdin), Main returns, and the deferred work runs. A second signal hard-exits in case something is genuinely stuck.

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>
@c-tonneslan c-tonneslan requested a review from a team as a code owner May 18, 2026 14:20
@c-tonneslan c-tonneslan requested a review from BagToad May 18, 2026 14:20
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed ready-for-review and removed needs-triage needs to be reviewed labels May 18, 2026
@github-actions
Copy link
Copy Markdown

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 help wanted label when possible, as it helps us prioritize and track contributions.

@BagToad
Copy link
Copy Markdown
Member

BagToad commented May 22, 2026

Closing due to contribution guidelines (no help wanted label)

@BagToad BagToad closed this May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing top-level signal handler causes defers to be skipped on ctrl+c

2 participants