From 82ba3615a21abb7b44d8964fa43e8d919e65da67 Mon Sep 17 00:00:00 2001 From: Antoine Mercadal Date: Mon, 26 Aug 2019 14:18:51 -0700 Subject: [PATCH] fixed/manipmongo: do not check deadline for context in retry --- manipmongo/helpers.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/manipmongo/helpers.go b/manipmongo/helpers.go index f1004896..917f838f 100644 --- a/manipmongo/helpers.go +++ b/manipmongo/helpers.go @@ -12,7 +12,6 @@ package manipmongo import ( - "context" "fmt" "strconv" "strings" @@ -231,12 +230,14 @@ func RunQuery(mctx manipulate.Context, operationFunc func() (interface{}, error) } } - deadline, ok := mctx.Context().Deadline() - if ok && deadline.Before(time.Now()) { - return nil, manipulate.NewErrCannotExecuteQuery(context.DeadlineExceeded.Error()) + select { + case <-mctx.Context().Done(): + return nil, manipulate.NewErrCannotExecuteQuery(mctx.Context().Err().Error()) + default: } - <-time.After(backoff.Next(try, deadline)) + deadline, _ := mctx.Context().Deadline() + time.Sleep(backoff.Next(try, deadline)) try++ } }