mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-10-29 17:52:32 +00:00
Exit DynamoDB tryToLock when stop channel is closed (#6640)
* Exit DynamoDB tryToLock when stop channel is closed If the stop channel is closed (e.g. an error is returned which triggers close(stop) in Lock), this loop will spin and use 100% CPU. * Ensure ticker is stopped
This commit is contained in:
@@ -600,11 +600,12 @@ func (l *DynamoDBLock) Value() (bool, string, error) {
|
||||
// channel is closed.
|
||||
func (l *DynamoDBLock) tryToLock(stop, success chan struct{}, errors chan error) {
|
||||
ticker := time.NewTicker(DynamoDBLockRetryInterval)
|
||||
defer ticker.Stop()
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-stop:
|
||||
ticker.Stop()
|
||||
return
|
||||
case <-ticker.C:
|
||||
err := l.updateItem(true)
|
||||
if err != nil {
|
||||
@@ -620,7 +621,6 @@ func (l *DynamoDBLock) tryToLock(stop, success chan struct{}, errors chan error)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
ticker.Stop()
|
||||
close(success)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user