mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
give LockWithContext a little backoff
Backoff the Lock calls exponentially, to a reasonable limit.
This commit is contained in:
parent
5eca913b14
commit
93b1dd6323
@ -75,8 +75,10 @@ type Locker interface {
|
||||
}
|
||||
|
||||
// Lock the state, using the provided context for timeout and cancellation.
|
||||
// TODO: this should probably backoff somewhat.
|
||||
// This backs off slightly to an upper limit.
|
||||
func LockWithContext(ctx context.Context, s State, info *LockInfo) (string, error) {
|
||||
delay := time.Second
|
||||
maxDelay := 16 * time.Second
|
||||
for {
|
||||
id, err := s.Lock(info)
|
||||
if err == nil {
|
||||
@ -99,7 +101,10 @@ func LockWithContext(ctx context.Context, s State, info *LockInfo) (string, erro
|
||||
case <-ctx.Done():
|
||||
// return the last lock error with the info
|
||||
return "", err
|
||||
case <-time.After(time.Second):
|
||||
case <-time.After(delay):
|
||||
if delay < maxDelay {
|
||||
delay *= 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user