From ed18ffdca3876ecc962bbfefe6f50d89fc2f1f88 Mon Sep 17 00:00:00 2001 From: Runchao Han Date: Mon, 17 Jun 2019 21:30:12 +1000 Subject: [PATCH] p2p: refactor Switch#OnStop (#3729) --- node/node.go | 1 - p2p/switch.go | 6 +----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/node/node.go b/node/node.go index 46185847e..6f2cad1e5 100644 --- a/node/node.go +++ b/node/node.go @@ -714,7 +714,6 @@ func (n *Node) OnStop() { n.indexerService.Stop() // now stop the reactors - // TODO: gracefully disconnect from peers. n.sw.Stop() // stop mempool WAL diff --git a/p2p/switch.go b/p2p/switch.go index 31e0aa6e1..7e681d67c 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -221,11 +221,7 @@ func (sw *Switch) OnStart() error { func (sw *Switch) OnStop() { // Stop peers for _, p := range sw.peers.List() { - sw.transport.Cleanup(p) - p.Stop() - if sw.peers.Remove(p) { - sw.metrics.Peers.Add(float64(-1)) - } + sw.stopAndRemovePeer(p, nil) } // Stop reactors