From a7b9987543b802fd85f2c67d82ed58892085ad29 Mon Sep 17 00:00:00 2001 From: Jim Kalafut Date: Mon, 29 Apr 2019 22:51:48 -0700 Subject: [PATCH] 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 --- physical/dynamodb/dynamodb.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/physical/dynamodb/dynamodb.go b/physical/dynamodb/dynamodb.go index c827ea2595..bfadbf0770 100644 --- a/physical/dynamodb/dynamodb.go +++ b/physical/dynamodb/dynamodb.go @@ -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 }