docs(telegram): clarify fallback-branch limits wiring vs siblings

Follow-up on the #58790 fallback-limits fix: tighten the now-stale
_with_limits docstring and note on the fallback branch why it injects
limits at the transport level (not via _with_limits) so a future editor
does not re-route it through the client-level helper httpx would discard.
This commit is contained in:
kshitijk4poor 2026-07-05 22:02:37 +05:30 committed by kshitij
parent 01ee312de6
commit 5b04a024a5

View file

@ -3025,8 +3025,11 @@ class TelegramAdapter(BasePlatformAdapter):
def _with_limits(httpx_kwargs: Optional[dict] = None) -> dict:
"""Merge tuned keepalive limits into httpx client kwargs.
A caller-supplied ``limits`` (none today) is left untouched;
otherwise the CLOSE_WAIT-safe limits are injected.
Used by the proxy and direct-DNS branches, where httpx honours
the client-level ``limits`` kwarg. A caller-supplied ``limits``
is left untouched; otherwise the CLOSE_WAIT-safe limits are
injected. The fallback-IP branch does NOT use this helper see
the ``_transport_kwargs`` note below for why.
"""
kwargs = dict(httpx_kwargs or {})
if _pool_limits is not None and "limits" not in kwargs:
@ -3055,9 +3058,12 @@ class TelegramAdapter(BasePlatformAdapter):
# Keep request/update pools separate to reduce contention during
# polling reconnect + bot API bootstrap/delete_webhook calls.
# httpx ignores the client-level `limits` kwarg when a custom
# `transport` is supplied (#58790). Pass the tuned limits
# `transport` is supplied (#58790). Unlike the proxy/direct
# branches (which inject limits at the client level via
# `_with_limits`), this branch MUST pass the tuned limits
# directly into TelegramFallbackTransport so its inner
# AsyncHTTPTransport instances honour keepalive_expiry.
# AsyncHTTPTransport instances honour keepalive_expiry — do not
# route this through `_with_limits`, httpx would discard it.
_transport_kwargs: dict = {}
if _pool_limits is not None:
_transport_kwargs["limits"] = _pool_limits