From 72280f31d4fd06038cfac312c8ce1c12e44884a7 Mon Sep 17 00:00:00 2001 From: Andrew Gillis <11790789+gammazero@users.noreply.github.com> Date: Thu, 4 Sep 2025 16:30:12 -0700 Subject: [PATCH] fix ctrl-c prompt during run migrations prompt (#10947) * fix ctrl-c prompt during run migrations prompt At "Run migrations" prompt, hitting ctrl-c does not show the "(Hit ctrl-c again to force-shutdown the daemon.)" prompt, even though a 2nd ctrl-c does cause the daemon to exit. The problem is that the goroutine that displays the prompt only run after the prompt to "Run migrations", so hitting ctrl-c during the "Run migrations" prompt does not show the "(Hit ctrl-c again to force-shutdown the daemon.)" prompt. This PR fixes the problem by starting the goroutine to display the "(Hit ctrl-c again to force-shutdown the daemon.)" prompt sooner, before the "Run mirgarions" prompt. Additionally, this PR also disables showing the ctrl-c prompt if the daemon function has already exited, in which case only the exit message should be shown. Closes #3157 * exit immediately if ctrl-c during migration prompt --- cmd/ipfs/kubo/daemon.go | 10 ++++++++++ cmd/ipfs/util/signal.go | 8 +------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/ipfs/kubo/daemon.go b/cmd/ipfs/kubo/daemon.go index 6c594912d..37f683fd5 100644 --- a/cmd/ipfs/kubo/daemon.go +++ b/cmd/ipfs/kubo/daemon.go @@ -284,6 +284,15 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment default: return err case fsrepo.ErrNeedMigration: + migrationDone := make(chan struct{}) + go func() { + select { + case <-req.Context.Done(): + os.Exit(1) + case <-migrationDone: + } + }() + domigrate, found := req.Options[migrateKwd].(bool) // Get current repo version for more informative message @@ -299,6 +308,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment if !found { domigrate = YesNoPrompt("Run migrations now? [y/N]") } + close(migrationDone) if !domigrate { fmt.Printf("Not running migrations on repository at %s. Re-run daemon with --migrate or see 'ipfs repo migrate --help'\n", cctx.ConfigRoot) diff --git a/cmd/ipfs/util/signal.go b/cmd/ipfs/util/signal.go index 2cfd0d5bd..3cbe2481d 100644 --- a/cmd/ipfs/util/signal.go +++ b/cmd/ipfs/util/signal.go @@ -64,13 +64,7 @@ func SetupInterruptHandler(ctx context.Context) (io.Closer, context.Context) { switch count { case 1: fmt.Println() // Prevent un-terminated ^C character in terminal - - ih.wg.Add(1) - go func() { - defer ih.wg.Done() - cancelFunc() - }() - + cancelFunc() default: fmt.Println("Received another interrupt before graceful shutdown, terminating...") os.Exit(-1)