Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #65 from manover/fix_connection_leak
Browse files Browse the repository at this point in the history
Fix connection leaks caused by a stale job queue
  • Loading branch information
jehiah committed Apr 25, 2013
2 parents d9c9c79 + 160a373 commit 3b33c15
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
10 changes: 8 additions & 2 deletions asyncmongo/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ def _socket_close(self):
if callback:
callback(None, InterfaceError('connection closed'))
finally:
# Flush the job queue, don't call the callbacks associated with the remaining jobs
# since they have already been called as error callback on connection closing
self.__job_queue = []
self.__alive = False
self.__pool.cache(self)

Expand All @@ -139,6 +142,9 @@ def _close(self):
if callback:
callback(None, InterfaceError('connection closed'))
finally:
# Flush the job queue, don't call the callbacks associated with the remaining jobs
# since they have already been called as error callback on connection closing
self.__job_queue = []
self.__alive = False
self.__stream.close()

Expand Down Expand Up @@ -232,9 +238,9 @@ def _parse_response(self, response):
self.__request_id = None
self.__callback = None
if not self.__job_queue:
# skip adding to the cache because there is something else
# skip adding to the cache because there is something else
# that needs to be called on this connection for this request
# (ie: we authenticted, but still have to send the real req)
# (ie: we authenticated, but still have to send the real req)
self.__pool.cache(self)

try:
Expand Down
1 change: 1 addition & 0 deletions asyncmongo/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def get_connection_pool(self, pool_id, *args, **kwargs):
self._pools = {}
if pool_id not in self._pools:
self._pools[pool_id] = ConnectionPool(*args, **kwargs)
# logging.debug("%s: _connections = %d", pool_id, self._pools[pool_id]._connections)
return self._pools[pool_id]

@classmethod
Expand Down

0 comments on commit 3b33c15

Please sign in to comment.