Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix async cancellation behaviour" #627

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions httpcore/_async/connection_pool.py
Expand Up @@ -214,9 +214,9 @@ async def handle_async_request(self, request: Request) -> Response:
)

status = RequestStatus(request)
self._requests.append(status)

async with self._pool_lock:
self._requests.append(status)
await self._close_expired_connections()
await self._attempt_to_acquire_connection(status)

Expand All @@ -229,8 +229,9 @@ async def handle_async_request(self, request: Request) -> Response:
# If we timeout here, or if the task is cancelled, then make
# sure to remove the request from the queue before bubbling
# up the exception.
self._requests.remove(status)
raise exc
async with self._pool_lock:
self._requests.remove(status)
raise exc

try:
response = await connection.handle_async_request(request)
Expand Down Expand Up @@ -273,11 +274,10 @@ async def response_closed(self, status: RequestStatus) -> None:
assert status.connection is not None
connection = status.connection

if status in self._requests:
self._requests.remove(status)

async with self._pool_lock:
# Update the state of the connection pool.
if status in self._requests:
self._requests.remove(status)

if connection.is_closed() and connection in self._pool:
self._pool.remove(connection)
Expand Down
12 changes: 6 additions & 6 deletions httpcore/_sync/connection_pool.py
Expand Up @@ -214,9 +214,9 @@ def handle_request(self, request: Request) -> Response:
)

status = RequestStatus(request)
self._requests.append(status)

with self._pool_lock:
self._requests.append(status)
self._close_expired_connections()
self._attempt_to_acquire_connection(status)

Expand All @@ -229,8 +229,9 @@ def handle_request(self, request: Request) -> Response:
# If we timeout here, or if the task is cancelled, then make
# sure to remove the request from the queue before bubbling
# up the exception.
self._requests.remove(status)
raise exc
with self._pool_lock:
self._requests.remove(status)
raise exc

try:
response = connection.handle_request(request)
Expand Down Expand Up @@ -273,11 +274,10 @@ def response_closed(self, status: RequestStatus) -> None:
assert status.connection is not None
connection = status.connection

if status in self._requests:
self._requests.remove(status)

with self._pool_lock:
# Update the state of the connection pool.
if status in self._requests:
self._requests.remove(status)

if connection.is_closed() and connection in self._pool:
self._pool.remove(connection)
Expand Down