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:
parent
41cb0f577f
commit
67d68c2fc8
@ -297,10 +297,9 @@ class IMAPServer:
|
||||
self.delim = imaputil.dequote(self.delim)
|
||||
self.root = imaputil.dequote(self.root)
|
||||
|
||||
self.connectionlock.acquire()
|
||||
with self.connectionlock:
|
||||
self.assignedconnections.append(imapobj)
|
||||
self.lastowner[imapobj] = curThread.ident
|
||||
self.connectionlock.release()
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user