Skip to content

fix(sftp): honor ctx cancellation in find and recursive get#4856

Open
Lucais11 wants to merge 1 commit intomasterfrom
fix/sftp-respect-ctrlc
Open

fix(sftp): honor ctx cancellation in find and recursive get#4856
Lucais11 wants to merge 1 commit intomasterfrom
fix/sftp-respect-ctrlc

Conversation

@Lucais11
Copy link
Copy Markdown
Contributor

@Lucais11 Lucais11 commented Apr 23, 2026

Fixes #4657

fly sftp find and fly sftp get -R iterate a pkg/sftp walker over remote directory listings without ever checking the context passed into the command. flyctl's root context is already wired to SIGINT via signal.NotifyContext in main.go, so Ctrl-C cancels the context immediately — but the walker loops never ask, leaving the command running until the tree is exhausted.

Add a per-iteration ctx.Err() check at the top of each loop body, matching the existing flyctl idiom (see internal/command/curl/curl.go). Returning context.Canceled is silenced by the root handler in internal/cli/cli.go, producing a clean exit with code 127 — same UX as fly ssh console on Ctrl-C.

`fly sftp find` and `fly sftp get -R` iterate a `pkg/sftp` walker over
remote directory listings without ever checking the context passed
into the command. flyctl's root context is already wired to SIGINT
via `signal.NotifyContext` in main.go, so Ctrl-C cancels the context
immediately — but the walker loops never ask, leaving the command
running until the tree is exhausted.

Add a per-iteration `ctx.Err()` check at the top of each loop body,
matching the existing flyctl idiom (see internal/command/curl/curl.go).
Returning `context.Canceled` is silenced by the root handler in
internal/cli/cli.go, producing a clean exit with code 127 — same UX
as `fly ssh console` on Ctrl-C.

The same pattern exists in `sftpContext.getDir` (called from the
interactive `fly sftp shell`), but that path lacks a ctx and requires
rethinking Ctrl-C semantics inside the readline shell. Left as a
follow-up.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fly sftp find can not be aborted

1 participant