From ddfa5cac1fe9ce602b7b8b5624122cc46f83d62a Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Mon, 2 Jan 2023 17:52:58 +0100 Subject: msgstore: fix deadlock in thread builder When scrolling while the thread builder is running, aerc freezes. This issue can be easily reproduced by keeping the down arrow pressed while a folder is loading with local threading enabled. This is caused by the threadCallback function calling store.Select which acquires threadsMutex. However, threadCallback is already called with threadsMutex acquired, causing a deadlock. Fix the issue by adding a new selectPriv function that does not acquire the lock and call this one in threadCallback *and* store.Select. Do not reset threadCallback to nil as it was before. Fixes: 6b8e0b19d35a ("split: refactor to prevent stuck splits") Signed-off-by: Robin Jarry Tested-by: Thomas Vigouroux --- lib/msgstore.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/msgstore.go b/lib/msgstore.go index 1a56b2c8..8b2d0419 100644 --- a/lib/msgstore.go +++ b/lib/msgstore.go @@ -613,6 +613,10 @@ func (store *MessageStore) Select(uid uint32) { store.threadCallback = nil } store.threadsMutex.Unlock() + store.selectPriv(uid) +} + +func (store *MessageStore) selectPriv(uid uint32) { store.selectedUid = uid if store.marker != nil { store.marker.UpdateVisualMark() @@ -647,7 +651,7 @@ func (store *MessageStore) NextPrev(delta int) { store.threadsMutex.Lock() store.threadCallback = func() { if uids := store.Uids(); len(uids) > newIdx { - store.Select(uids[newIdx]) + store.selectPriv(uids[newIdx]) } } store.threadsMutex.Unlock() -- cgit