diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-09-25 14:38:47 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-09-26 17:32:00 +0200 |
commit | 978768bff66e5f98f8cbf63ee19dd91fc4ca2bf3 (patch) | |
tree | 0eac71a199f5c4291a0b6cffe06407fa94c2e693 | |
parent | 9e54c921c83fedb3b816e1a98b30e1ff2a10b542 (diff) | |
download | aerc-978768bff66e5f98f8cbf63ee19dd91fc4ca2bf3.tar.gz |
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 <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r-- | worker/imap/idler.go | 18 |
1 files 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) } |