Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/s2_sdk/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ async def _reap_idle(self) -> None:
await asyncio.sleep(REAPER_INTERVAL)
empty_hosts: list[str] = []
for base_url, conns in tuple(self._hosts.items()):
num_usable_conns = sum(
not pc.is_retired and pc._conn.is_available for pc in conns
)
to_close: list[_PooledConnection] = []
for pc in conns:
if pc.is_retired:
Expand All @@ -444,9 +447,10 @@ async def _reap_idle(self) -> None:
elif (
pc.is_idle
and pc.idle_for() > IDLE_TIMEOUT
and len(conns) - len(to_close) > 1
and num_usable_conns > 1
):
to_close.append(pc)
num_usable_conns -= 1
for pc in to_close:
conns.remove(pc)
for pc in to_close:
Expand Down
Loading