Skip to content

Commit 72280f3

Browse files
authored
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
1 parent 46cc640 commit 72280f3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

cmd/ipfs/kubo/daemon.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,15 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
284284
default:
285285
return err
286286
case fsrepo.ErrNeedMigration:
287+
migrationDone := make(chan struct{})
288+
go func() {
289+
select {
290+
case <-req.Context.Done():
291+
os.Exit(1)
292+
case <-migrationDone:
293+
}
294+
}()
295+
287296
domigrate, found := req.Options[migrateKwd].(bool)
288297

289298
// Get current repo version for more informative message
@@ -299,6 +308,7 @@ func daemonFunc(req *cmds.Request, re cmds.ResponseEmitter, env cmds.Environment
299308
if !found {
300309
domigrate = YesNoPrompt("Run migrations now? [y/N]")
301310
}
311+
close(migrationDone)
302312

303313
if !domigrate {
304314
fmt.Printf("Not running migrations on repository at %s. Re-run daemon with --migrate or see 'ipfs repo migrate --help'\n", cctx.ConfigRoot)

cmd/ipfs/util/signal.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,7 @@ func SetupInterruptHandler(ctx context.Context) (io.Closer, context.Context) {
6464
switch count {
6565
case 1:
6666
fmt.Println() // Prevent un-terminated ^C character in terminal
67-
68-
ih.wg.Add(1)
69-
go func() {
70-
defer ih.wg.Done()
71-
cancelFunc()
72-
}()
73-
67+
cancelFunc()
7468
default:
7569
fmt.Println("Received another interrupt before graceful shutdown, terminating...")
7670
os.Exit(-1)

0 commit comments

Comments
 (0)