Browse Source

p2p: do not panic when filter times out (#3384)

Fixes #3369
pull/3407/head
Anton Kaliaev 6 years ago
committed by GitHub
parent
commit
100ff08de9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 2 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +8
    -1
      p2p/switch.go
  3. +39
    -0
      p2p/switch_test.go
  4. +1
    -1
      p2p/transport.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -46,3 +46,4 @@ CI/CD: * [\#3396](https://github.com/tendermint/tendermint/pull/3396)
- [p2p/conn] \#3347 Reject all-zero shared secrets in the Diffie-Hellman step of secret-connection
- [libs/pubsub] \#951, \#1880 use non-blocking send when dispatching messages [ADR-33](https://github.com/tendermint/tendermint/blob/develop/docs/architecture/adr-033-pubsub.md)
- [p2p] \#3369 do not panic when filter times out

+ 8
- 1
p2p/switch.go View File

@ -497,7 +497,14 @@ func (sw *Switch) acceptRoutine() {
)
continue
case *ErrTransportClosed:
case ErrFilterTimeout:
sw.Logger.Error(
"Peer filter timed out",
"err", err,
)
continue
case ErrTransportClosed:
sw.Logger.Error(
"Stopped accept routine, as transport is closed",
"numPeers", sw.peers.Size(),


+ 39
- 0
p2p/switch_test.go View File

@ -2,6 +2,7 @@ package p2p
import (
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
@ -532,6 +533,44 @@ func TestSwitchAcceptRoutine(t *testing.T) {
}
}
type errorTransport struct {
acceptErr error
}
func (et errorTransport) Accept(c peerConfig) (Peer, error) {
return nil, et.acceptErr
}
func (errorTransport) Dial(NetAddress, peerConfig) (Peer, error) {
panic("not implemented")
}
func (errorTransport) Cleanup(Peer) {
panic("not implemented")
}
func TestSwitchAcceptRoutineErrorCases(t *testing.T) {
sw := NewSwitch(cfg, errorTransport{ErrFilterTimeout{}})
assert.NotPanics(t, func() {
err := sw.Start()
assert.NoError(t, err)
sw.Stop()
})
sw = NewSwitch(cfg, errorTransport{ErrRejected{conn: nil, err: errors.New("filtered"), isFiltered: true}})
assert.NotPanics(t, func() {
err := sw.Start()
assert.NoError(t, err)
sw.Stop()
})
// TODO(melekes) check we remove our address from addrBook
sw = NewSwitch(cfg, errorTransport{ErrTransportClosed{}})
assert.NotPanics(t, func() {
err := sw.Start()
assert.NoError(t, err)
sw.Stop()
})
}
func BenchmarkSwitchBroadcast(b *testing.B) {
s1, s2 := MakeSwitchPair(b, func(i int, sw *Switch) *Switch {
// Make bar reactors of bar channels each


+ 1
- 1
p2p/transport.go View File

@ -175,7 +175,7 @@ func (mt *MultiplexTransport) Accept(cfg peerConfig) (Peer, error) {
return mt.wrapPeer(a.conn, a.nodeInfo, cfg, nil), nil
case <-mt.closec:
return nil, &ErrTransportClosed{}
return nil, ErrTransportClosed{}
}
}


Loading…
Cancel
Save