Skip to content

Commit 17cfa53

Browse files
committed
Revert "fix ugly error message when killing commands"
This reverts commit f74e71f. The 'Online' flag of the command context does not seem to be set in any code paths, at least not when running commands such as 'ipfs daemon' or 'ipfs ping'. The result after f74e71f is that we never shutdown cleanly, as we'll always os.Exit(0) from the interrupt handler. The os.Exit(0) itself is also dubious, as conceptually the interrupt handler should ask whatever is stalling to stop stalling, so that main() can return like normal. Exiting with -1 in error cases where the interrupt handler is unable to stop the stall is fine, but the normal case of interrupting cleanly should exit through main().
1 parent e225e9f commit 17cfa53

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

cmd/ipfs/main.go

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -496,24 +496,22 @@ func (i *cmdInvocation) setupInterruptHandler() {
496496
case <-ctx.InitDone:
497497
}
498498

499+
// TODO cancel the command context instead
500+
501+
n, err := ctx.GetNode()
502+
if err != nil {
503+
log.Error(err)
504+
fmt.Println(shutdownMessage)
505+
os.Exit(-1)
506+
}
507+
499508
switch count {
500509
case 0:
501510
fmt.Println(shutdownMessage)
502-
if ctx.Online {
503-
go func() {
504-
// TODO cancel the command context instead
505-
n, err := ctx.GetNode()
506-
if err != nil {
507-
log.Error(err)
508-
fmt.Println(shutdownMessage)
509-
os.Exit(-1)
510-
}
511-
n.Close()
512-
log.Info("Gracefully shut down.")
513-
}()
514-
} else {
515-
os.Exit(0)
516-
}
511+
go func() {
512+
n.Close()
513+
log.Info("Gracefully shut down.")
514+
}()
517515

518516
default:
519517
fmt.Println("Received another interrupt before graceful shutdown, terminating...")

0 commit comments

Comments
 (0)