From f1935bc0ff180fa7e476450583248f07b40056d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Rainone?= <476650+arl@users.noreply.github.com> Date: Mon, 9 Dec 2019 16:21:20 +0100 Subject: [PATCH] Fix potentially delayed shutdown on shard sync (#64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ull-request #62 wrongly introduced an increased delay on shutdown. Before #62 the `stop` channel could be triggered while waiting for `syncShard` milliseconds, so the function could return as soon as `stop` was received. However #62 changed this behavior by sleeping in the default case: `stop` couldn't be handled right away anymore. Instead it was handled after a whole new loop, potentially delaying shutdown by minutes. (up to synchard * 1.5 ms). This commit fixes that. Signed-off-by: Aurélien Rainone --- clientlibrary/worker/worker.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/clientlibrary/worker/worker.go b/clientlibrary/worker/worker.go index 13eb8d9..95c1acd 100644 --- a/clientlibrary/worker/worker.go +++ b/clientlibrary/worker/worker.go @@ -315,9 +315,8 @@ func (w *Worker) eventLoop() { case <-*w.stop: log.Infof("Shutting down...") return - default: - log.Debugf("Trying to sync shards in %d ms...", shardSyncSleep) - time.Sleep(time.Duration(shardSyncSleep) * time.Millisecond) + case <-time.After(time.Duration(shardSyncSleep) * time.Millisecond): + log.Debugf("Waited %d ms to sync shards...", shardSyncSleep) } } }