Skip to content

Commit

Permalink
[3.8] Fix race condition on connect when tracing is active (#5259) (#…
Browse files Browse the repository at this point in the history
…5285) (#5291)

Co-authored-by: Bob Haddleton <bobh66@users.noreply.github.com>
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
  • Loading branch information
3 people committed Nov 26, 2020
1 parent dd682fb commit 71b9394
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES/5259.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Acquire the connection before running traces to prevent race condition.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Arthur Darcet
Ben Bader
Ben Timby
Benedikt Reinartz
Bob Haddleton
Boris Feld
Boyi Chen
Brett Cannon
Expand Down
6 changes: 6 additions & 0 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,14 @@ async def connect(
await trace.send_connection_create_end()
else:
if traces:
# Acquire the connection to prevent race conditions with limits
placeholder = cast(ResponseHandler, _TransportPlaceholder())
self._acquired.add(placeholder)
self._acquired_per_host[key].add(placeholder)
for trace in traces:
await trace.send_connection_reuseconn()
self._acquired.remove(placeholder)
self._drop_acquired_per_host(key, placeholder)

self._acquired.add(proto)
self._acquired_per_host[key].add(proto)
Expand Down

0 comments on commit 71b9394

Please sign in to comment.