Skip to content

Commit 3a53583

Browse files
Revert "Fix async cancellation behaviour (#580)" (#627)
This reverts commit ce8f872.
1 parent a2f86ca commit 3a53583

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

httpcore/_async/connection_pool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ async def handle_async_request(self, request: Request) -> Response:
214214
)
215215

216216
status = RequestStatus(request)
217-
self._requests.append(status)
218217

219218
async with self._pool_lock:
219+
self._requests.append(status)
220220
await self._close_expired_connections()
221221
await self._attempt_to_acquire_connection(status)
222222

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

235236
try:
236237
response = await connection.handle_async_request(request)
@@ -273,11 +274,10 @@ async def response_closed(self, status: RequestStatus) -> None:
273274
assert status.connection is not None
274275
connection = status.connection
275276

276-
if status in self._requests:
277-
self._requests.remove(status)
278-
279277
async with self._pool_lock:
280278
# Update the state of the connection pool.
279+
if status in self._requests:
280+
self._requests.remove(status)
281281

282282
if connection.is_closed() and connection in self._pool:
283283
self._pool.remove(connection)

httpcore/_sync/connection_pool.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,9 @@ def handle_request(self, request: Request) -> Response:
214214
)
215215

216216
status = RequestStatus(request)
217-
self._requests.append(status)
218217

219218
with self._pool_lock:
219+
self._requests.append(status)
220220
self._close_expired_connections()
221221
self._attempt_to_acquire_connection(status)
222222

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

235236
try:
236237
response = connection.handle_request(request)
@@ -273,11 +274,10 @@ def response_closed(self, status: RequestStatus) -> None:
273274
assert status.connection is not None
274275
connection = status.connection
275276

276-
if status in self._requests:
277-
self._requests.remove(status)
278-
279277
with self._pool_lock:
280278
# Update the state of the connection pool.
279+
if status in self._requests:
280+
self._requests.remove(status)
281281

282282
if connection.is_closed() and connection in self._pool:
283283
self._pool.remove(connection)

0 commit comments

Comments
 (0)