aboutsummaryrefslogtreecommitdiffstats
path: root/lib/msgstore.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-09-29 16:27:05 -0500
committerRobin Jarry <robin@jarry.cc>2022-10-02 18:58:52 +0200
commit8cd4770f329c749c801630d1ec29c2765e60a8e6 (patch)
tree904f2f7c05cdd112db2bbff76bb7ae18480e0b24 /lib/msgstore.go
parentdc299cc8adda5c9fb7a0f6a7719f3e2cd0f1f443 (diff)
downloadaerc-8cd4770f329c749c801630d1ec29c2765e60a8e6.tar.gz
msgstore: fix data race on access to store.needsFlags
Flag fetching is debounced in the UI, creating a race condition where fields are accessed in the AfterFunc. Protect the needsFlags field with a mutex. Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r--lib/msgstore.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index d2d4b6e6..74a021a7 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -14,6 +14,7 @@ import (
// Accesses to fields must be guarded by MessageStore.Lock/Unlock
type MessageStore struct {
+ sync.Mutex
Deleted map[uint32]interface{}
DirInfo models.DirectoryInfo
Messages map[uint32]*models.MessageInfo
@@ -247,7 +248,9 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
store.Messages[msg.Info.Uid] = msg.Info
}
if msg.NeedsFlags {
+ store.Lock()
store.needsFlags = append(store.needsFlags, msg.Info.Uid)
+ store.Unlock()
store.fetchFlags()
}
seen := false
@@ -757,9 +760,11 @@ func (store *MessageStore) fetchFlags() {
store.fetchFlagsDebounce.Stop()
}
store.fetchFlagsDebounce = time.AfterFunc(store.fetchFlagsDelay, func() {
+ store.Lock()
store.worker.PostAction(&types.FetchMessageFlags{
Uids: store.needsFlags,
}, nil)
store.needsFlags = []uint32{}
+ store.Unlock()
})
}