From cad89029dd1a4f64700f07deb7bbfb978de69507 Mon Sep 17 00:00:00 2001 From: Derek Menteer Date: Mon, 31 Oct 2022 13:50:58 -0500 Subject: [PATCH] Decrease retry time for failed peering connections. --- agent/consul/leader_peering.go | 6 ++++-- agent/consul/leader_peering_test.go | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/agent/consul/leader_peering.go b/agent/consul/leader_peering.go index 471bb01c8..602e311df 100644 --- a/agent/consul/leader_peering.go +++ b/agent/consul/leader_peering.go @@ -65,6 +65,8 @@ var ( maxFastConnRetries = uint(5) // maxFastRetryBackoff is the maximum amount of time we'll wait between retries following the fast path. maxFastRetryBackoff = 8192 * time.Millisecond + // maxRetryBackoffPeering is the maximum number of seconds we'll wait between retries when attempting to re-establish a peering connection. + maxRetryBackoffPeering = 64 ) func (s *Server) startPeeringStreamSync(ctx context.Context) { @@ -713,10 +715,10 @@ func peeringRetryTimeout(failedAttempts uint, loopErr error) time.Duration { } // Else we go with the default backoff from retryLoopBackoff. - if (1 << failedAttempts) < maxRetryBackoff { + if (1 << failedAttempts) < maxRetryBackoffPeering { return (1 << failedAttempts) * time.Second } - return time.Duration(maxRetryBackoff) * time.Second + return time.Duration(maxRetryBackoffPeering) * time.Second } // isErrCode returns true if err is a gRPC error with given error code. diff --git a/agent/consul/leader_peering_test.go b/agent/consul/leader_peering_test.go index 84f4dbbaf..ddd3cad7f 100644 --- a/agent/consul/leader_peering_test.go +++ b/agent/consul/leader_peering_test.go @@ -1586,10 +1586,12 @@ func TestLeader_Peering_peeringRetryTimeout_regularErrors(t *testing.T) { {1, 2 * time.Second}, {2, 4 * time.Second}, {3, 8 * time.Second}, + {4, 16 * time.Second}, + {5, 32 * time.Second}, // Until max. - {8, 256 * time.Second}, - {9, 256 * time.Second}, - {10, 256 * time.Second}, + {6, 64 * time.Second}, + {10, 64 * time.Second}, + {20, 64 * time.Second}, } for _, c := range cases {