mirror of
https://github.com/tendermint/tendermint.git
synced 2026-05-22 15:11:29 +00:00
p2p: avoid sending errors after context is canceled (#8548)
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user