From 978768bff66e5f98f8cbf63ee19dd91fc4ca2bf3 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Sun, 25 Sep 2022 14:38:47 -0500 Subject: idler: fix data race for access to idleing and waiting Protect access to fields idleing and waiting via a mutex. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- worker/imap/idler.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/worker/imap/idler.go b/worker/imap/idler.go index 4c2ce6e8..65ba6b9b 100644 --- a/worker/imap/idler.go +++ b/worker/imap/idler.go @@ -60,6 +60,18 @@ func (i *idler) isReady() bool { i.client.State() == imap.SelectedState) } +func (i *idler) setIdleing(v bool) { + i.Lock() + defer i.Unlock() + i.idleing = v +} + +func (i *idler) isIdleing() bool { + i.Lock() + defer i.Unlock() + return i.idleing +} + func (i *idler) Start() { switch { case i.isReady(): @@ -74,7 +86,7 @@ func (i *idler) Start() { i.done <- nil case <-time.After(i.config.idle_debounce): // enter idle mode - i.idleing = true + i.setIdleing(true) i.log("=>(idle)") now := time.Now() err := i.client.Idle(i.stop, @@ -82,7 +94,7 @@ func (i *idler) Start() { LogoutTimeout: 0, PollInterval: 0, }) - i.idleing = false + i.setIdleing(false) i.done <- err i.log("elapsed idle time: %v", time.Since(now)) } @@ -154,5 +166,5 @@ func (i *idler) waitOnIdle() { func (i *idler) log(format string, v ...interface{}) { msg := fmt.Sprintf(format, v...) - logging.Debugf("idler (%p) [idle:%t,wait:%t] %s", i, i.idleing, i.waiting, msg) + logging.Debugf("idler (%p) [idle:%t,wait:%t] %s", i, i.isIdleing(), i.isWaiting(), msg) } -- cgit