From 36e4eaff991eb0bcb9bb6bd5c2244ce670a8768d Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 11 Jun 2019 12:20:00 +0200 Subject: [PATCH 1/4] document retry.Backoff better --- common/retry/retry.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/common/retry/retry.go b/common/retry/retry.go index 2b1a4f231..3189c4c97 100644 --- a/common/retry/retry.go +++ b/common/retry/retry.go @@ -76,12 +76,23 @@ func (cfg Config) Run(ctx context.Context, fn func(context.Context) error) error } } +// Backoff is a self contained backoff time calculator. This struct should be +// passed around as a copy as it changes its own fields upon any Backoff call. +// Backoff is not thread safe. For now only a Linear backoff call is +// implemented and the Exponential call will be implemented when needed. type Backoff struct { + // Initial time to wait. A Backoff call will change this value. InitialBackoff time.Duration - MaxBackoff time.Duration - Multiplier float64 + // Maximum time returned. + MaxBackoff time.Duration + // For a Linear backoff, InitialBackoff will be multiplied by Multiplier + // after each call. + Multiplier float64 } +// Linear Backoff returns a linearly increasing Duration. +// n = n * Multiplier. +// the first value of n is InitialBackoff. n is maxed by MaxBackoff. func (lb *Backoff) Linear() time.Duration { wait := lb.InitialBackoff lb.InitialBackoff = time.Duration(lb.Multiplier * float64(lb.InitialBackoff)) @@ -90,3 +101,8 @@ func (lb *Backoff) Linear() time.Duration { } return wait } + +// Exponential backoff panics: not implemented, yet. +func (lb *Backoff) Exponential() time.Duration { + panic("not implemented, yet") +} From 98206d59d764025906589c3eb0ba644fd7688a56 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 11 Jun 2019 12:37:52 +0200 Subject: [PATCH 2/4] aws: step_create_tags make the max waiting time 30s and not 30ns --- builder/amazon/common/step_create_tags.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builder/amazon/common/step_create_tags.go b/builder/amazon/common/step_create_tags.go index 337bc1daa..68adc9878 100644 --- a/builder/amazon/common/step_create_tags.go +++ b/builder/amazon/common/step_create_tags.go @@ -102,7 +102,7 @@ func (s *StepCreateTags) Run(ctx context.Context, state multistep.StateBag) mult } return false }, - RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30, Multiplier: 2}).Linear, + RetryDelay: (&retry.Backoff{InitialBackoff: 200 * time.Millisecond, MaxBackoff: 30 * time.Second, Multiplier: 2}).Linear, }.Run(ctx, func(ctx context.Context) error { // Tag images and snapshots From 39cfacd5fa6a7317a4c9f8658a1753812cc48bc0 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 11 Jun 2019 12:41:21 +0200 Subject: [PATCH 3/4] Backoff.Linear: panic when InitialBackoff > MaxBackoff this probably means there's a configuration issue. Since this struct is mainly set manually from code, I think it is okay to panic here. --- common/retry/retry.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/retry/retry.go b/common/retry/retry.go index 3189c4c97..38e2ba88d 100644 --- a/common/retry/retry.go +++ b/common/retry/retry.go @@ -94,6 +94,9 @@ type Backoff struct { // n = n * Multiplier. // the first value of n is InitialBackoff. n is maxed by MaxBackoff. func (lb *Backoff) Linear() time.Duration { + if lb.InitialBackoff > lb.MaxBackoff { + panic("InitialBackoff > MaxBackoff, did you forgot setting the seconds ?") + } wait := lb.InitialBackoff lb.InitialBackoff = time.Duration(lb.Multiplier * float64(lb.InitialBackoff)) if lb.MaxBackoff != 0 && lb.InitialBackoff > lb.MaxBackoff { From ca33f8bc5c23aea3e5025001b0e179b88c8eccc7 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Tue, 11 Jun 2019 12:53:06 +0200 Subject: [PATCH 4/4] Revert "Backoff.Linear: panic when InitialBackoff > MaxBackoff" This reverts commit 39cfacd5fa6a7317a4c9f8658a1753812cc48bc0. --- common/retry/retry.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/common/retry/retry.go b/common/retry/retry.go index 38e2ba88d..3189c4c97 100644 --- a/common/retry/retry.go +++ b/common/retry/retry.go @@ -94,9 +94,6 @@ type Backoff struct { // n = n * Multiplier. // the first value of n is InitialBackoff. n is maxed by MaxBackoff. func (lb *Backoff) Linear() time.Duration { - if lb.InitialBackoff > lb.MaxBackoff { - panic("InitialBackoff > MaxBackoff, did you forgot setting the seconds ?") - } wait := lb.InitialBackoff lb.InitialBackoff = time.Duration(lb.Multiplier * float64(lb.InitialBackoff)) if lb.MaxBackoff != 0 && lb.InitialBackoff > lb.MaxBackoff {