Allow Imapserver.releaseconnection() to drop a connection
If a connection is broken, we want to have it really dropped and not be reused. So far, we are checking the .Terminate attribute for this, but according to the imaplib2 author, it is only set on normal shutdown and it is an undocumented attribute whose meaning could change any time. This patch introduces the parameter drop_conn which allows to tell releaseconnection() that we really want to connection being dropped from the pool of available connections and properly destroy it. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
1917be8e83
commit
971ed3adac
@ -109,12 +109,15 @@ class IMAPServer:
|
||||
return self.root
|
||||
|
||||
|
||||
def releaseconnection(self, connection):
|
||||
"""Releases a connection, returning it to the pool."""
|
||||
def releaseconnection(self, connection, drop_conn=False):
|
||||
"""Releases a connection, returning it to the pool.
|
||||
|
||||
:param drop_conn: If True, the connection will be released and
|
||||
not be reused. This can be used to indicate broken connections."""
|
||||
self.connectionlock.acquire()
|
||||
self.assignedconnections.remove(connection)
|
||||
# Don't reuse broken connections
|
||||
if connection.Terminate:
|
||||
if connection.Terminate or drop_conn:
|
||||
connection.logout()
|
||||
else:
|
||||
self.availableconnections.append(connection)
|
||||
|
Loading…
Reference in New Issue
Block a user