Revert "fix ugly error message when killing commands"
This reverts commit f74e71f96545b14f5293c9851ce624aecddb68aa. 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 f74e71f9 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().
Tor Arne Vestbø committed
Apr 17, 2015 at 18:45 UTC
61efc4de1de6b3e43baf885be37b33dd55a88039
1 file changed
+13
-15
cmd/ipfs/main.go
+13
-15
@@ -495,24 +495,22 @@ func (i *cmdInvocation) setupInterruptHandler() {
495
case <-ctx.InitDone:
496
}
497
498
+ // TODO cancel the command context instead
499
+
500
+ n, err := ctx.GetNode()
501
+ if err != nil {
502
+ log.Error(err)
503
+ fmt.Println(shutdownMessage)
504
+ os.Exit(-1)
505
+ }
506
+
507
switch count {
508
case 0:
509
fmt.Println(shutdownMessage)
501
- if ctx.Online {
502
- go func() {
503
- // TODO cancel the command context instead
504
- n, err := ctx.GetNode()
505
- if err != nil {
506
- log.Error(err)
507
- fmt.Println(shutdownMessage)
508
- os.Exit(-1)
509
- }
510
- n.Close()
511
- log.Info("Gracefully shut down.")
512
- }()
513
- } else {
514
- os.Exit(0)
515
- }
510
+ go func() {
511
+ n.Close()
512
+ log.Info("Gracefully shut down.")
513
+ }()
514
515
default:
516
fmt.Println("Received another interrupt before graceful shutdown, terminating...")