Browse Source

ignore ErrAlreadyStarted when starting addrbook in PEXReactor

pull/807/head
Anton Kaliaev 7 years ago
parent
commit
691e266bef
No known key found for this signature in database GPG Key ID: 7B6881D965918214
3 changed files with 6 additions and 12 deletions
  1. +1
    -1
      p2p/pex_reactor.go
  2. +2
    -4
      p2p/pex_reactor_test.go
  3. +3
    -7
      p2p/switch.go

+ 1
- 1
p2p/pex_reactor.go View File

@ -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()


+ 2
- 4
p2p/pex_reactor_test.go View File

@ -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)


+ 3
- 7
p2p/switch.go View File

@ -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()


Loading…
Cancel
Save