Skip to content
Myr

Release semaphore if connection is dropped (#230)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Ordanis Sanchez · committed by Seth Michael Larson · parent 9c7d23c · Browse files · 2 files+19 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+19 added−0 removed

  • tests:+18 added−0 removed
  • other:+1 added−0 removed

2 files+19 added−0 removed

modified:httpx/dispatch/connection_pool.py+1 added
121 unmodified lines
122 if connection is None:123 connection = self.keepalive_connections.pop_by_origin(origin)124125 if connection is not None and connection.is_connection_dropped():126 self.max_connections.release()127 connection = None128129 if connection is None:130 await self.max_connections.acquire()
34 unmodified lines
modified:tests/dispatch/test_connection_pools.py+18 added
169 unmodified lines
170 response = await http.request("GET", "http://127.0.0.1:8000/")171 await response.read()172 assert len(http.active_connections) == 0173 assert len(http.keepalive_connections) == 1174175176@pytest.mark.asyncio177async def test_connection_closed_free_semaphore_on_acquire(server):178 """179 Verify that max_connections semaphore is released180 properly on a disconnected connection.181 """182 async with httpx.ConnectionPool(pool_limits=httpx.PoolLimits(hard_limit=1)) as http:183 response = await http.request("GET", "http://127.0.0.1:8000/")184 await response.read()185186 # Close the connection so we're forced to recycle it187 await server.shutdown()188 await server.startup()189190 response = await http.request("GET", "http://127.0.0.1:8000/")191 assert response.status_code == 200