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:
Jim Kalafut
2019-04-29 22:51:48 -07:00
committed by GitHub
parent 0950939a23
commit a7b9987543

View File

@@ -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
}