Prevent synchronization of identical folders from multiple threads

Use a mutex to lock both local and remote folders before doing
synchronization.  This prevents IDLE threads from downloading the same
messages as autorefresh threads (this could have resulted in
downloading new messages twice, or reading "one message past the last
one" which in some cases created a duplicate an IMAP folder's first
message).  Also prevents IDLE threads from reading new messages before
the autorefresh thread finishes synchronization.

Fixes #421.

Signed-off-by: Michael Hohmuth <hohmuth@sax.de>
This commit is contained in:
Michael Hohmuth 2017-02-24 21:58:53 +01:00
parent d5edf2dc11
commit e12f008d39
2 changed files with 8 additions and 0 deletions

View File

@ -528,6 +528,9 @@ def syncfolder(account, remotefolder, quick):
# Load local folder.
localfolder = account.get_local_folder(remotefolder)
localfolder.mutex.acquire()
remotefolder.mutex.acquire()
# Add the folder to the mbnames mailboxes.
mbnames.add(account.name, localrepos.getlocalroot(),
localfolder.getname())
@ -616,3 +619,5 @@ def syncfolder(account, remotefolder, quick):
if folder in locals():
locals()[folder].dropmessagelistcache()
statusfolder.closefiles()
remotefolder.mutex.release()
localfolder.mutex.release()

View File

@ -19,6 +19,7 @@ import os.path
import re
import time
from sys import exc_info
from threading import Lock
from offlineimap import threadutil
from offlineimap.ui import getglobalui
@ -91,6 +92,8 @@ class BaseFolder(object):
self.__syncmessagesto_flags,
]
self.mutex = Lock()
def getname(self):
"""Returns name"""
return self.name