Browse Source

p2p: remove unnecessary panic handling in PEX reactor (#8110)

The message handling in this reactor is all under control of the reactor
itself, and does not call out to callbacks or other externally-supplied code.
It doesn't need to check for panics.

- Remove an irrelevant channel ID check.
- Remove an unnecessary panic recovery wrapper.
pull/8114/head
M. J. Fromberger 3 years ago
committed by GitHub
parent
commit
658a7661c5
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 24 deletions
  1. +1
    -24
      internal/p2p/pex/reactor.go

+ 1
- 24
internal/p2p/pex/reactor.go View File

@ -3,7 +3,6 @@ package pex
import ( import (
"context" "context"
"fmt" "fmt"
"runtime/debug"
"sync" "sync"
"time" "time"
@ -192,7 +191,7 @@ func (r *Reactor) processPexCh(ctx context.Context) {
} }
// A request from another peer, or a response to one of our requests. // A request from another peer, or a response to one of our requests.
dur, err := r.handleMessage(ctx, r.pexCh.ID, envelope)
dur, err := r.handlePexMessage(ctx, envelope)
if err != nil { if err != nil {
r.logger.Error("failed to process message", r.logger.Error("failed to process message",
"ch_id", r.pexCh.ID, "envelope", envelope, "err", err) "ch_id", r.pexCh.ID, "envelope", envelope, "err", err)
@ -287,28 +286,6 @@ func (r *Reactor) handlePexMessage(ctx context.Context, envelope *p2p.Envelope)
} }
} }
// handleMessage handles an Envelope sent from a peer on the specified Channel.
// This method will convert a panic in message handling as an error.
func (r *Reactor) handleMessage(ctx context.Context, chID p2p.ChannelID, envelope *p2p.Envelope) (_ time.Duration, err error) {
defer func() {
if e := recover(); e != nil {
err = fmt.Errorf("panic in processing message: %v", e)
r.logger.Error(
"recovering from processing message panic",
"err", err,
"stack", string(debug.Stack()),
)
}
}()
r.logger.Debug("received PEX message", "peer", envelope.From)
if chID == p2p.ChannelID(PexChannel) {
return r.handlePexMessage(ctx, envelope)
}
return 0, fmt.Errorf("unknown channel ID (%d) for envelope (%v)", chID, envelope)
}
// processPeerUpdate processes a PeerUpdate. For added peers, PeerStatusUp, we // processPeerUpdate processes a PeerUpdate. For added peers, PeerStatusUp, we
// send a request for addresses. // send a request for addresses.
func (r *Reactor) processPeerUpdate(peerUpdate p2p.PeerUpdate) { func (r *Reactor) processPeerUpdate(peerUpdate p2p.PeerUpdate) {


Loading…
Cancel
Save