p2p: avoid sending errors after context is canceled (#8548)

This commit is contained in:
Sam Kleinman
2022-05-14 08:28:09 -04:00
committed by GitHub
parent b43336b706
commit 9db41016ab
2 changed files with 17 additions and 0 deletions

View File

@@ -153,6 +153,15 @@ func (r *Reactor) handleMempoolMessage(ctx context.Context, envelope *p2p.Envelo
// problem.
continue
}
if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
// Do not propagate context
// cancellation errors, but do
// not continue to check
// transactions from this
// message if we are shutting down.
return nil
}
logger.Error("checktx failed for tx",
"tx", fmt.Sprintf("%X", types.Tx(tx).Hash()),
"err", err)

View File

@@ -105,6 +105,10 @@ func (ch *legacyChannel) Send(ctx context.Context, envelope Envelope) error {
// SendError blocks until the given error has been sent, or ctx ends.
// An error only occurs if the context ends before the send completes.
func (ch *legacyChannel) SendError(ctx context.Context, pe PeerError) error {
if errors.Is(pe.Err, context.Canceled) || errors.Is(pe.Err, context.DeadlineExceeded) {
return nil
}
select {
case <-ctx.Done():
return ctx.Err()
@@ -414,6 +418,10 @@ func (ch *libp2pChannelImpl) Send(ctx context.Context, e Envelope) error {
}
func (ch *libp2pChannelImpl) SendError(ctx context.Context, pe PeerError) error {
if errors.Is(pe.Err, context.Canceled) || errors.Is(pe.Err, context.DeadlineExceeded) || ctx.Err() != nil {
return nil
}
// TODO: change handling of errors to peers. This problably
// shouldn't be handled as a property of the channel, and
// rather as part of some peer-info/network-management