From aab08b90501fefef0acac160ede0ed25f94d3daa Mon Sep 17 00:00:00 2001 From: Mike Monaghan Date: Tue, 13 Sep 2022 15:31:16 -0600 Subject: [PATCH] fixing infinite worker loop Signed-off-by: Mike Monaghan --- clientlibrary/worker/worker.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/clientlibrary/worker/worker.go b/clientlibrary/worker/worker.go index 7807edd..f68e949 100644 --- a/clientlibrary/worker/worker.go +++ b/clientlibrary/worker/worker.go @@ -272,6 +272,14 @@ func (w *Worker) eventLoop() { rnd, _ := rand.Int(rand.Reader, big.NewInt(int64(w.kclConfig.ShardSyncIntervalMillis))) shardSyncSleep := w.kclConfig.ShardSyncIntervalMillis/2 + int(rnd.Int64()) + select { + case <-*w.stop: + log.Infof("Shutting down...") + return + case <-time.After(time.Duration(shardSyncSleep) * time.Millisecond): + log.Debugf("Waited %d ms to sync shards...", shardSyncSleep) + } + err := w.syncShard() if err != nil { log.Errorf("Error syncing shards: %+v, Retrying in %d ms...", err, shardSyncSleep) @@ -363,14 +371,6 @@ func (w *Worker) eventLoop() { log.Warnf("Error in rebalance: %+v", err) } } - - select { - case <-*w.stop: - log.Infof("Shutting down...") - return - case <-time.After(time.Duration(shardSyncSleep) * time.Millisecond): - log.Debugf("Waited %d ms to sync shards...", shardSyncSleep) - } } }