diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 81c7a3a29..450c6a5df 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -9,9 +9,11 @@ BREAKING CHANGES: * Apps * Go API +- [node] Remove node.RunForever FEATURES: IMPROVEMENTS: BUG FIXES: +- [node] \#2434 Make node respond to signal interrupts while sleeping for genesis time diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index 542e5c991..6dabacb1f 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -2,6 +2,9 @@ package commands import ( "fmt" + "os" + "os/signal" + "syscall" "github.com/spf13/cobra" @@ -49,19 +52,31 @@ func NewRunNodeCmd(nodeProvider nm.NodeProvider) *cobra.Command { Use: "node", Short: "Run the tendermint node", RunE: func(cmd *cobra.Command, args []string) error { - // Create & start node n, err := nodeProvider(config, logger) if err != nil { return fmt.Errorf("Failed to create node: %v", err) } + // Stop upon receiving SIGTERM or CTRL-C + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + go func() { + for sig := range c { + logger.Error(fmt.Sprintf("captured %v, exiting...", sig)) + if n.IsRunning() { + n.Stop() + } + os.Exit(1) + } + }() + if err := n.Start(); err != nil { return fmt.Errorf("Failed to start node: %v", err) } logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo()) - // Trap signal, run forever. - n.RunForever() + // Run forever + select {} return nil }, diff --git a/node/node.go b/node/node.go index 0e5581a56..016ed367b 100644 --- a/node/node.go +++ b/node/node.go @@ -586,14 +586,6 @@ func (n *Node) OnStop() { } } -// RunForever waits for an interrupt signal and stops the node. -func (n *Node) RunForever() { - // Sleep forever and then... - cmn.TrapSignal(func() { - n.Stop() - }) -} - // ConfigureRPC sets all variables in rpccore so they will serve // rpc calls from this node func (n *Node) ConfigureRPC() { diff --git a/p2p/transport.go b/p2p/transport.go index 61cff55d9..903d193d9 100644 --- a/p2p/transport.go +++ b/p2p/transport.go @@ -207,7 +207,11 @@ func (mt *MultiplexTransport) Dial( func (mt *MultiplexTransport) Close() error { close(mt.closec) - return mt.listener.Close() + if mt.listener != nil { + return mt.listener.Close() + } + + return nil } // Listen implements transportLifecycle. diff --git a/types/event_bus.go b/types/event_bus.go index d11c65205..466ae7b44 100644 --- a/types/event_bus.go +++ b/types/event_bus.go @@ -45,7 +45,7 @@ func (b *EventBus) SetLogger(l log.Logger) { } func (b *EventBus) OnStart() error { - return b.pubsub.OnStart() + return b.pubsub.Start() } func (b *EventBus) OnStop() {