Skip to content

Commit

Permalink
p2p: remove unnecessary panic handling in PEX reactor (tendermint#8110)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
M. J. Fromberger authored Mar 11, 2022
1 parent 89b4321 commit 658a766
Showing 1 changed file with 1 addition and 24 deletions.
25 changes: 1 addition & 24 deletions internal/p2p/pex/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package pex
import (
"context"
"fmt"
"runtime/debug"
"sync"
"time"

Expand Down Expand Up @@ -192,7 +191,7 @@ func (r *Reactor) processPexCh(ctx context.Context) {
}

// 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 {
r.logger.Error("failed to process message",
"ch_id", r.pexCh.ID, "envelope", envelope, "err", err)
Expand Down Expand Up @@ -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
// send a request for addresses.
func (r *Reactor) processPeerUpdate(peerUpdate p2p.PeerUpdate) {
Expand Down

0 comments on commit 658a766

Please sign in to comment.