Skip to content

Commit 9757638

Browse files
Jim KalafutBrian Kassouf
authored andcommitted
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
1 parent 7db6f22 commit 9757638

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

physical/dynamodb/dynamodb.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,11 +600,12 @@ func (l *DynamoDBLock) Value() (bool, string, error) {
600600
// channel is closed.
601601
func (l *DynamoDBLock) tryToLock(stop, success chan struct{}, errors chan error) {
602602
ticker := time.NewTicker(DynamoDBLockRetryInterval)
603+
defer ticker.Stop()
603604

604605
for {
605606
select {
606607
case <-stop:
607-
ticker.Stop()
608+
return
608609
case <-ticker.C:
609610
err := l.updateItem(true)
610611
if err != nil {
@@ -620,7 +621,6 @@ func (l *DynamoDBLock) tryToLock(stop, success chan struct{}, errors chan error)
620621
return
621622
}
622623
} else {
623-
ticker.Stop()
624624
close(success)
625625
return
626626
}

0 commit comments

Comments
 (0)