Skip to content

Commit

Permalink
Fix race condition on connect when tracing is active (aio-libs#5259)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobh66 committed Nov 24, 2020
1 parent 6f73339 commit 1be1dfb
Show file tree
Hide file tree
Showing 2 changed files with 7 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.
6 changes: 6 additions & 0 deletions aiohttp/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,8 +525,14 @@ async def connect(
await trace.send_connection_create_end()
else:
if traces:
# Acquire the connection to prevent race conditions while hendling traces
placeholder = cast(ResponseHandler, _TransportPlaceholder(self._loop))
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 1be1dfb

Please sign in to comment.