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)