Skip to content

Commit

Permalink
node: Respond always to OS interrupts (#2479)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
melekes authored and xla committed Sep 25, 2018
1 parent d297f02 commit d12e55c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 18 additions & 3 deletions cmd/tendermint/commands/run_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package commands

import (
"fmt"
"os"
"os/signal"
"syscall"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -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
},
Expand Down
8 changes: 0 additions & 8 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 5 additions & 1 deletion p2p/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion types/event_bus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit d12e55c

Please sign in to comment.