Skip to content

fix: drain general httpx connection pool on Telegram send pool timeout - #41391

Closed
jackdaw-talks wants to merge 1 commit into
NousResearch:mainfrom
jackdaw-talks:fix/telegram-drain-general-pool
Closed

fix: drain general httpx connection pool on Telegram send pool timeout#41391
jackdaw-talks wants to merge 1 commit into
NousResearch:mainfrom
jackdaw-talks:fix/telegram-drain-general-pool

Conversation

@jackdaw-talks

Copy link
Copy Markdown

Summary

When Telegram's httpx connection pool for general requests exhausts due to
stuck connections, only the polling pool is drained. This adds drain for send pool.

See commit for full details.

Add _drain_general_connections() to reset the general request pool
(_request[1]) when pool timeout is detected during send/edit operations,
mirroring the existing _drain_polling_connections() pattern for the
polling pool (_request[0]).

Previously only the polling pool was drained on reconnect, leaving
send_message and edit_message permanently degraded when the general pool
exhausted, requiring a full gateway restart to recover.
@alt-glitch alt-glitch added type/bug Something isn't working P1 High — major feature broken, no workaround comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter labels Jun 7, 2026
@liuhao1024

Copy link
Copy Markdown
Contributor

✅ Verified — httpx connection pool exhaustion fix

Reviewed the diff for Telegram send/edit path reliability under pool exhaustion.

  • New method _drain_general_connections() at gateway/platforms/telegram.py:945: Correctly targets only _request[1] (general/send pool), leaving _request[0] (getUpdates polling) untouched — polling continues uninterrupted during drain
  • Pool lifecycle: shutdown()initialize() sequence is correct for httpx pool reset
  • Integration points: drain is called in 3 error paths — send retry (send() line 2093), send error return (send() line 2162), and edit_message error (edit_message() line 2323). All wrapped in try/except for non-fatal handling
  • Internal API access (_request[1]) acknowledged with # noqa: SLF001

The fix addresses a real production scenario: half-closed connections from proxy interruptions (e.g., sing-box) gradually exhausting the pool until all sends fail with Pool timeout. Thorough coverage of all error paths. No issues found.

@teknium1 teknium1 added sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jun 21, 2026
@teknium1

Copy link
Copy Markdown
Contributor

Automated hermes-sweeper review: this older PR's fix is already implemented on current main.

Evidence:

Thanks for the diagnosis and patch. The behavior this PR targeted is now covered on main, so closing this as implemented there.

@teknium1 teknium1 closed this Jun 29, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P1 High — major feature broken, no workaround platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:implemented-on-main Sweeper: behavior already present on current main sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants