Skip to content

Commit

Permalink
only _release should need to use discard, it would be a bug if it nee…
Browse files Browse the repository at this point in the history
…ded to use it in connect which we want to catch
  • Loading branch information
bdraco committed Nov 5, 2024
1 parent 5deb957 commit 449e589
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,14 +368,6 @@ def _cleanup(self) -> None:
timeout_ceil_threshold=self._timeout_ceil_threshold,
)

def _drop_acquired(self, key: "ConnectionKey", val: ResponseHandler) -> None:
"""Drop acquired connection."""
self._acquired.discard(val)
if conns := self._acquired_per_host.get(key):
conns.discard(val)
if not conns:
del self._acquired_per_host[key]

def _cleanup_closed(self) -> None:
"""Double confirmation for transport close.
Expand Down Expand Up @@ -535,9 +527,11 @@ async def connect(
# be no awaits after the proto is added to the acquired set
# to ensure that the connection is not left in the acquired set
# on cancellation.
self._drop_acquired(key, placeholder)
acquired_per_host = self._acquired_per_host[key]
self._acquired.remove(placeholder)
acquired_per_host.remove(placeholder)
self._acquired.add(proto)
self._acquired_per_host[key].add(proto)
acquired_per_host.add(proto)
return Connection(self, key, proto, self._loop)

async def _wait_for_available_connection(
Expand Down Expand Up @@ -657,7 +651,11 @@ def _release_acquired(self, key: "ConnectionKey", proto: ResponseHandler) -> Non
# acquired connection is already released on connector closing
return

self._drop_acquired(key, proto)
self._acquired.discard(proto)
if conns := self._acquired_per_host.get(key):
conns.discard(proto)
if not conns:
del self._acquired_per_host[key]
self._release_waiter()

def _release(
Expand Down

0 comments on commit 449e589

Please sign in to comment.