fix(telegram): drain general send pool on pool timeout before retry (#53524) - #54121
Merged
Conversation
Contributor
🔎 Lint report:
|
This was referenced Jun 28, 2026
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Telegram replies stop reaching the user once the general send pool wedges: the send path treats a pool timeout as retryable but never resets
_request[1], so retries keep hammering the dead httpx client and silently drop the reply. This drains and re-inits the general Bot API pool on a confirmed pool timeout before retrying.Salvage of #53622 by @yungchentang. Fixes #53524.
Changes
plugins/platforms/telegram/adapter.py: add_drain_general_connections_after_pool_timeout()(shutdown + reinit of_request[1]), guarded by anasyncio.Lockso concurrent sends can't tear the pool down mid-request. The send retry loop calls it when_looks_like_pool_timeout()matches, before the next attempt. The polling-pool drain (_request[0]) is left exactly as-is.tests/gateway/test_telegram_thread_fallback.py: regression test — a pool timeout drains_request[1]before retry and leaves_request[0]untouched.Why this isn't a duplicate of #51541
Merged #51541 added keepalive limits to the general pool to prevent the slow CLOSE_WAIT fd bleed. It explicitly noted the general pool still had no acute-recovery path when it does wedge. This PR closes exactly that gap — complementary, not redundant. (The issue's
force_close_tcp_sockets/launchd framing is a stale mental model: that symbol lives inrun_agent.pyfor agent HTTP/TLS fd recycle, unrelated to the Telegram adapter.)Validation
_request[0])asyncio.Lock, no mid-send teardownscripts/run_tests.sh tests/gateway/test_telegram_thread_fallback.py tests/gateway/test_telegram_closewait_limits_31599.py→ 50 passed.Infographic