Skip to content

Commit

Permalink
Fix cleanup of empty pool keys in connector
Browse files Browse the repository at this point in the history
Issues aio-libs#253 and aio-libs#254 implemented a `_conns` key evince logic in the
function that actually **adds** items to `_conns`

Issue aio-libs#406 tweaked this logic even more, making early and eviction
of reusable items in the pool possible.

Here we put the key eviction logic where it belongs: in the method
that **removes** items from the `_conns` pool.
  • Loading branch information
Marco Paolini committed Aug 22, 2015
1 parent 549a0d9 commit 28c7da4
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,10 @@ def connect(self, req):
return conn

def _get(self, key):
conns = self._conns.get(key)
try:
conns = self._conns[key]
except KeyError:
return None, None
t1 = self._loop.time()
while conns:
transport, proto, t0 = conns.pop()
Expand All @@ -313,7 +316,9 @@ def _get(self, key):
transport = None
else:
return transport, proto

# No more connections for this key. Drop refs to transport and protocol
# that make the key
del self._conns[key]
return None, None

def _release(self, key, req, transport, protocol, *, should_close=False):
Expand Down Expand Up @@ -351,15 +356,6 @@ def _release(self, key, req, transport, protocol, *, should_close=False):

reader = protocol.reader
if should_close or (reader.output and not reader.output.at_eof()):
conns = self._conns.get(key)
if conns is not None and len(conns) >= 0:
# Issue #253: An empty array will eventually be
# removed by cleanup, but it's better to pop straight
# away, because cleanup might not get called (e.g. if
# keepalive is False).
if not acquired:
self._conns.pop(key, None)

transport.close()
else:
conns = self._conns.get(key)
Expand Down

0 comments on commit 28c7da4

Please sign in to comment.