From 4b63efcbeec0095a689e18c74063f6f2bee588f1 Mon Sep 17 00:00:00 2001 From: Ivan Trubach Date: Fri, 7 May 2021 11:05:18 +0300 Subject: [PATCH] fix(rpc): drop request on context deadline This change makes the RPC engine drop the request when parent context reaches deadline. That is, before this change a deadline from context.WithTimeout would not drop the request. --- internal/rpc/engine.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/rpc/engine.go b/internal/rpc/engine.go index b80b32de91..a58f3cf2c5 100644 --- a/internal/rpc/engine.go +++ b/internal/rpc/engine.go @@ -140,12 +140,12 @@ func (e *Engine) Do(ctx context.Context, req Request) error { // Start retrying. sent, err := e.retryUntilAck(retryCtx, req) - if err != nil && !errors.Is(err, context.Canceled) { + if err != nil && !errors.Is(err, retryCtx.Err()) { // If the retryCtx was canceled, then one of two things happened: - // 1. User canceled the original context. + // 1. User canceled the parent context. // 2. The RPC result came and callback canceled retryCtx. // - // If this is not an context.Canceled error, most likely we did not receive ack + // If this is not a Context’s error, most likely we did not receive ack // and exceeded the limit of attempts to send a request, // or could not write data to the connection, so we return an error. return xerrors.Errorf("retryUntilAck: %w", err)