Browse Source

node: Respond always to OS interrupts (#2479)

* stop node upon receiving SIGTERM or CTRL-Ceven during genesis sleep by setting up interrupt before starting a node

Closes #2434

* call Start, not OnStart when starting a component to avoid:

```
E[09-24|10:13:15.805] Not stopping PubSub -- have not been started yet module=pubsub impl=PubSub
```

being printed on exit
pull/2486/merge
Anton Kaliaev 6 years ago
committed by Alexander Simmerl
parent
commit
d12e55c494
5 changed files with 26 additions and 13 deletions
  1. +2
    -0
      CHANGELOG_PENDING.md
  2. +18
    -3
      cmd/tendermint/commands/run_node.go
  3. +0
    -8
      node/node.go
  4. +5
    -1
      p2p/transport.go
  5. +1
    -1
      types/event_bus.go

+ 2
- 0
CHANGELOG_PENDING.md View File

@ -9,9 +9,11 @@ BREAKING CHANGES:
* Apps * Apps
* Go API * Go API
- [node] Remove node.RunForever
FEATURES: FEATURES:
IMPROVEMENTS: IMPROVEMENTS:
BUG FIXES: BUG FIXES:
- [node] \#2434 Make node respond to signal interrupts while sleeping for genesis time

+ 18
- 3
cmd/tendermint/commands/run_node.go View File

@ -2,6 +2,9 @@ package commands
import ( import (
"fmt" "fmt"
"os"
"os/signal"
"syscall"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -49,19 +52,31 @@ func NewRunNodeCmd(nodeProvider nm.NodeProvider) *cobra.Command {
Use: "node", Use: "node",
Short: "Run the tendermint node", Short: "Run the tendermint node",
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
// Create & start node
n, err := nodeProvider(config, logger) n, err := nodeProvider(config, logger)
if err != nil { if err != nil {
return fmt.Errorf("Failed to create node: %v", err) 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 { if err := n.Start(); err != nil {
return fmt.Errorf("Failed to start node: %v", err) return fmt.Errorf("Failed to start node: %v", err)
} }
logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo()) logger.Info("Started node", "nodeInfo", n.Switch().NodeInfo())
// Trap signal, run forever.
n.RunForever()
// Run forever
select {}
return nil return nil
}, },


+ 0
- 8
node/node.go View File

@ -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 // ConfigureRPC sets all variables in rpccore so they will serve
// rpc calls from this node // rpc calls from this node
func (n *Node) ConfigureRPC() { func (n *Node) ConfigureRPC() {


+ 5
- 1
p2p/transport.go View File

@ -207,7 +207,11 @@ func (mt *MultiplexTransport) Dial(
func (mt *MultiplexTransport) Close() error { func (mt *MultiplexTransport) Close() error {
close(mt.closec) close(mt.closec)
return mt.listener.Close()
if mt.listener != nil {
return mt.listener.Close()
}
return nil
} }
// Listen implements transportLifecycle. // Listen implements transportLifecycle.


+ 1
- 1
types/event_bus.go View File

@ -45,7 +45,7 @@ func (b *EventBus) SetLogger(l log.Logger) {
} }
func (b *EventBus) OnStart() error { func (b *EventBus) OnStart() error {
return b.pubsub.OnStart()
return b.pubsub.Start()
} }
func (b *EventBus) OnStop() { func (b *EventBus) OnStop() {


Loading…
Cancel
Save