IMAP: simplify locking and fix potential lock loss
Run the locked code under 'with': this guarantees that lock will be released in any case. This modification also avoids the case when our thread wasn't running locked when exception was caught, another thread got the lock, our code checked it via self.connectionlock.locked() and errorneously released the lock thinking that is was running locked. Signed-off-by: Eygene Ryabinkin <rea@codelabs.ru>
This commit is contained in:
@ -297,10 +297,9 @@ class IMAPServer:
|
||||
self.delim = imaputil.dequote(self.delim)
|
||||
self.root = imaputil.dequote(self.root)
|
||||
|
||||
self.connectionlock.acquire()
|
||||
self.assignedconnections.append(imapobj)
|
||||
self.lastowner[imapobj] = curThread.ident
|
||||
self.connectionlock.release()
|
||||
with self.connectionlock:
|
||||
self.assignedconnections.append(imapobj)
|
||||
self.lastowner[imapobj] = curThread.ident
|
||||
return imapobj
|
||||
except Exception as e:
|
||||
"""If we are here then we did not succeed in getting a
|
||||
@ -308,9 +307,6 @@ class IMAPServer:
|
||||
error..."""
|
||||
self.semaphore.release()
|
||||
|
||||
if(self.connectionlock.locked()):
|
||||
self.connectionlock.release()
|
||||
|
||||
severity = OfflineImapError.ERROR.REPO
|
||||
if type(e) == gaierror:
|
||||
#DNS related errors. Abort Repo sync
|
||||
|
Reference in New Issue
Block a user