Skip to content

Commit

Permalink
🔥 remove warning about unresponsive pool of connections (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ousret authored Apr 4, 2024
1 parent dc7c91f commit 9bc003f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2.7.903 (2024-04-04)
====================

- Removed warning about "unresponsive" pool of connection due to how it can confuse users.

2.7.902 (2024-04-03)
====================

Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/_async/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ async def urlopen(
try:
# Request a connection from the queue.
timeout_obj = self._get_timeout(timeout)
await self.pool.wait_for_available_or_available_slot()
await self.pool.wait_for_unallocated_or_available_slot()
conn = await self._get_conn(timeout=pool_timeout, heb_timeout=timeout_obj)

conn.timeout = timeout_obj.connect_timeout # type: ignore[assignment]
Expand Down
2 changes: 1 addition & 1 deletion src/urllib3/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is protected via CODEOWNERS
from __future__ import annotations

__version__ = "2.7.902"
__version__ = "2.7.903"
30 changes: 18 additions & 12 deletions src/urllib3/util/_async/traffic_police.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import contextlib
import contextvars
import typing
import warnings

from ..traffic_police import (
AtomicTraffic,
Expand Down Expand Up @@ -100,9 +99,11 @@ def bag_only_idle(self) -> bool:
traffic_state_of(_) == TrafficState.IDLE for _ in self._registry.values()
)

async def wait_for_available_or_available_slot(self) -> None:
async def wait_for_unallocated_or_available_slot(
self, timeout: float | None = None
) -> None:
"""Wait for EITHER free slot in the pool OR one conn is not saturated!"""
combined_wait: float = 0.0
warn_raised: bool = False

while True:
if self.maxsize is None: # case Inf.
Expand All @@ -121,17 +122,16 @@ async def wait_for_available_or_available_slot(self) -> None:
await asyncio.sleep(0.001)
combined_wait += 0.001

if not warn_raised and combined_wait >= 1.0:
warn_raised = True
warnings.warn(
"Your connection pool seems unresponsive, please try to "
"increase the maxsize capacity or release connections manually. "
"In case of pending requests, please consume them.",
UserWarning,
stacklevel=2,
if timeout is not None and combined_wait >= combined_wait:
raise TimeoutError(
"Timed out while waiting for conn_or_pool to become available"
)

async def wait_for_idle_or_available_slot(self) -> None:
async def wait_for_idle_or_available_slot(
self, timeout: float | None = None
) -> None:
combined_wait: float = 0.0

while True:
if self.maxsize is None: # case Inf.
return
Expand All @@ -147,6 +147,12 @@ async def wait_for_idle_or_available_slot(self) -> None:
return

await asyncio.sleep(0.001)
combined_wait += 0.001

if timeout is not None and combined_wait >= combined_wait:
raise TimeoutError(
"Timed out while waiting for conn_or_pool to become available"
)

def __len__(self) -> int:
return len(self._registry)
Expand Down

0 comments on commit 9bc003f

Please sign in to comment.