From 658a7661c517b3483a305da099d4ec74465e9c52 Mon Sep 17 00:00:00 2001 From: "M. J. Fromberger" Date: Fri, 11 Mar 2022 08:23:03 -0800 Subject: [PATCH] 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. --- internal/p2p/pex/reactor.go | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/internal/p2p/pex/reactor.go b/internal/p2p/pex/reactor.go index 3804552d9..2beaeaa17 100644 --- a/internal/p2p/pex/reactor.go +++ b/internal/p2p/pex/reactor.go @@ -3,7 +3,6 @@ package pex import ( "context" "fmt" - "runtime/debug" "sync" "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. - 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) @@ -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) {