Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions offlineimap/imapserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,6 @@ def _is_socket_alive(imapobj):
return False


def _check_pooled_connection(imapobj, ui):
"""Verify that a pooled connection is still alive by sending a NOOP command.
Returns True if the connection is healthy and False if it is not. Logs
any exceptions encountered during the NOOP command as debug messages, since
they are expected to occur when a connection has gone stale.
"""
try:
typ, _ = imapobj.noop()
return typ == 'OK'
except Exception as e:
ui.debug('imap', 'Pooled connection health check (NOOP) failed: %s' % e)
return False


class IMAPServer:
"""Initializes all variables from an IMAPRepository() instance

Expand Down Expand Up @@ -596,19 +582,12 @@ def acquireconnection(self):
# Verify that the connection is still alive before returning it
# to the caller. If not, clean up and recursively call
# acquireconnection() to get a new one.
if not _check_pooled_connection(imapobj, self.ui):
self.ui.debug('imap', 'Pooled connection to %s is dead, '
'creating a new one' % self.hostname)
# Clean up and release the slot to force a new connection
self.connectionlock.acquire()
self.assignedconnections.remove(imapobj)
self.connectionlock.release()
try:
imapobj.logout()
except Exception:
pass
self.semaphore.release()
return self.acquireconnection() # Recursive call to get a new connection
try:
imapobj.noop()
except imapobj.abort:
self.ui.warn('Connection %s is dead, dropping' % imapobj.identifier)
self.releaseconnection(imapobj, True)
return self.acquireconnection()

return imapobj

Expand Down