aerc/worker/imap
Robin Jarry 420f236d31 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>
2022-06-24 21:08:12 +02:00
..
cache.go imap: add option to cache headers 2022-06-22 11:26:13 +02:00
checkmail.go feat: add background mail polling option for all workers 2022-05-31 14:32:51 +02:00
configure.go imap: add option to cache headers 2022-06-22 11:26:13 +02:00
connect.go imap: add timeout to tcp connect functions 2022-05-04 14:07:15 +02:00
create.go go vet: composite literal uses unkeyed fields 2022-03-18 13:33:16 +01:00
fetch.go imap: fix data race on seqMap array 2022-06-24 21:08:12 +02:00
flags.go imap: fix data race on seqMap array 2022-06-24 21:08:12 +02:00
idler.go imap: add debouncer to the idler 2022-05-04 14:07:15 +02:00
imap.go go.mod: change base git url 2021-11-05 10:21:45 +01:00
list.go logging: added a log on panic 2022-03-23 20:56:09 +01:00
movecopy.go dirlist: update RUE counts for imap/maildir on move|copy|delete|archive 2022-06-07 16:19:23 +02:00
observer.go imap: monitor the logout channel with an observer 2022-05-04 14:07:15 +02:00
open.go imap: fix data race on seqMap array 2022-06-24 21:08:12 +02:00
remove.go go vet: composite literal uses unkeyed fields 2022-03-18 13:33:16 +01:00
search.go Add flag based search options 2020-07-25 08:08:08 +02:00
seqmap.go imap: fix data race on seqMap array 2022-06-24 21:08:12 +02:00
seqmap_test.go imap: fix data race on seqMap array 2022-06-24 21:08:12 +02:00
worker.go imap: fix data race on seqMap array 2022-06-24 21:08:12 +02:00