diff --git a/p2p/pex_reactor.go b/p2p/pex_reactor.go index fe55687e0..6e49f6d06 100644 --- a/p2p/pex_reactor.go +++ b/p2p/pex_reactor.go @@ -70,7 +70,7 @@ func (r *PEXReactor) OnStart() error { return err } err := r.book.Start() - if err != nil { + if err != nil && err != cmn.ErrAlreadyStarted { return err } go r.ensurePeersRoutine() diff --git a/p2p/pex_reactor_test.go b/p2p/pex_reactor_test.go index 7e97f78cc..e80840b17 100644 --- a/p2p/pex_reactor_test.go +++ b/p2p/pex_reactor_test.go @@ -62,13 +62,11 @@ func TestPEXReactorAddRemovePeer(t *testing.T) { } func TestPEXReactorRunning(t *testing.T) { - require := require.New(t) - N := 3 switches := make([]*Switch, N) dir, err := ioutil.TempDir("", "pex_reactor") - require.Nil(err) + require.Nil(t, err) defer os.RemoveAll(dir) // nolint: errcheck book := NewAddrBook(dir+"addrbook.json", false) book.SetLogger(log.TestingLogger()) @@ -96,7 +94,7 @@ func TestPEXReactorRunning(t *testing.T) { // start switches for _, s := range switches { err := s.Start() // start switch and reactors - require.Nil(err) + require.Nil(t, err) } assertSomePeersWithTimeout(t, switches, 10*time.Millisecond, 10*time.Second) diff --git a/p2p/switch.go b/p2p/switch.go index b72453a50..f41b82959 100644 --- a/p2p/switch.go +++ b/p2p/switch.go @@ -1,12 +1,13 @@ package p2p import ( - "errors" "fmt" "math/rand" "net" "time" + "github.com/pkg/errors" + crypto "github.com/tendermint/go-crypto" cfg "github.com/tendermint/tendermint/config" cmn "github.com/tendermint/tmlibs/common" @@ -174,17 +175,13 @@ func (sw *Switch) SetNodePrivKey(nodePrivKey crypto.PrivKeyEd25519) { // OnStart implements BaseService. It starts all the reactors, peers, and listeners. func (sw *Switch) OnStart() error { - if err := sw.BaseService.OnStart(); err != nil { - return err - } // Start reactors for _, reactor := range sw.reactors { err := reactor.Start() if err != nil { - return err + return errors.Wrapf(err, "failed to start %v", reactor) } } - // Start listeners for _, listener := range sw.listeners { go sw.listenerRoutine(listener) @@ -194,7 +191,6 @@ func (sw *Switch) OnStart() error { // OnStop implements BaseService. It stops all listeners, peers, and reactors. func (sw *Switch) OnStop() { - sw.BaseService.OnStop() // Stop listeners for _, listener := range sw.listeners { listener.Stop()