Skip to content

Commit 0e8bc1f

Browse files
Fix race condition when removing closed connections from the pool (#437)
1 parent d6c1fa8 commit 0e8bc1f

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

httpcore/_async/connection_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ async def response_closed(self, status: RequestStatus) -> None:
273273
# Update the state of the connection pool.
274274
self._requests.remove(status)
275275

276-
if connection.is_closed():
276+
if connection.is_closed() and connection in self._pool:
277277
self._pool.remove(connection)
278278

279279
# Since we've had a response closed, it's possible we'll now be able

httpcore/_sync/connection_pool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def response_closed(self, status: RequestStatus) -> None:
273273
# Update the state of the connection pool.
274274
self._requests.remove(status)
275275

276-
if connection.is_closed():
276+
if connection.is_closed() and connection in self._pool:
277277
self._pool.remove(connection)
278278

279279
# Since we've had a response closed, it's possible we'll now be able

0 commit comments

Comments
 (0)