From 3e79d58e4ad5703bf24061ecf5f4bdfdcc1607d1 Mon Sep 17 00:00:00 2001 From: Yoan Blanc Date: Mon, 11 Apr 2022 19:37:14 +0200 Subject: [PATCH] fix: use NewSafeTimer Signed-off-by: Yoan Blanc --- client/rpc.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/client/rpc.go b/client/rpc.go index 3dc33ef14..7d1dfb6e4 100644 --- a/client/rpc.go +++ b/client/rpc.go @@ -109,8 +109,11 @@ TRY: } // Wait to avoid thundering herd + timer, cancel := helper.NewSafeTimer(helper.RandomStagger(c.config.RPCHoldTimeout / structs.JitterFraction)) + defer cancel() + select { - case <-time.After(helper.RandomStagger(c.config.RPCHoldTimeout / structs.JitterFraction)): + case <-timer.C: // If we are going to retry a blocking query we need to update the time to block so it finishes by our deadline. if info, ok := args.(structs.RPCInfo); ok && info.TimeToBlock() > 0 { newBlockTime := time.Until(deadline)