diff options
author | Robin Jarry <robin@jarry.cc> | 2022-06-20 21:49:05 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-06-24 21:08:12 +0200 |
commit | 420f236d31da76df9982331c596b776ab3d0dd76 (patch) | |
tree | df1c0ee7612400aefd08f0ce260bbb421d50b491 /worker/imap/fetch.go | |
parent | 389c0f82a7f5dc250500fcff6570308cc3bcbd88 (diff) | |
download | aerc-420f236d31da76df9982331c596b776ab3d0dd76.tar.gz |
imap: fix data race on seqMap array
There are concurrent threads that are accessing and modifying
IMAPWorker.seqMap (the mapping of sequence numbers to message UIDs).
This can lead to crashes when trying to add and remove a message ID.
panic: runtime error: index out of range [391] with length 390
goroutine 1834 [running]:
git.sr.ht/~rjarry/aerc/logging.PanicHandler()
logging/panic-logger.go:47 +0x6de
panic({0xa41760, 0xc0019b3290})
/usr/lib/golang/src/runtime/panic.go:838 +0x207
git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessages.func1()
worker/imap/fetch.go:214 +0x185
created by git.sr.ht/~rjarry/aerc/worker/imap.(*IMAPWorker).handleFetchMessages
worker/imap/fetch.go:209 +0x12b
Use a map which makes more sense than a simple array for random access
operations. Also, it allows better typing for the key values. Protect
the map with a mutex. Add internal API to access the map. Add basic unit
tests to ensure that concurrent access works.
Fixes: https://todo.sr.ht/~rjarry/aerc/49
Signed-off-by: Robin Jarry <robin@jarry.cc>
Acked-by: Moritz Poldrack <moritz@poldrack.dev>
Diffstat (limited to 'worker/imap/fetch.go')
-rw-r--r-- | worker/imap/fetch.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/worker/imap/fetch.go b/worker/imap/fetch.go index e8a8251b..7d7b72fe 100644 --- a/worker/imap/fetch.go +++ b/worker/imap/fetch.go @@ -211,7 +211,7 @@ func (imapw *IMAPWorker) handleFetchMessages( var reterr error for _msg := range messages { - imapw.seqMap[_msg.SeqNum-1] = _msg.Uid + imapw.seqMap.Put(_msg.SeqNum, _msg.Uid) err := procFunc(_msg) if err != nil { if reterr == nil { |