Skip to content

Telegram gateway hangs due to connection pool exhaustion #9

@perejaslav

Description

@perejaslav

Bug Description

The Telegram gateway process becomes unresponsive after running for an extended period (observed: ~24+ hours). Messages sent to the bot in Telegram are not received, and the integration stops responding entirely.

Root Cause

The httpx connection pool used for Telegram Bot API requests becomes exhausted. The gateway log shows:

Pool timeout: All connections in the connection pool are occupied

Over time, connections to api.telegram.org are opened but not properly released back to the pool. Once all pool slots are occupied, new requests (including getUpdates polling) hang indefinitely, making the gateway non-functional.

Steps to Reproduce

  1. Start the gateway: hermes gateway run --replace
  2. Let it run for 24+ hours with normal Telegram activity
  3. The gateway stops responding to Telegram messages
  4. Log shows pool timeout errors

Current Workaround

Kill and restart the gateway process:

ps aux | grep "hermes_cli.main gateway" | grep -v grep
kill <PID>
cd ~/.hermes/hermes-agent && venv/bin/python -m hermes_cli.main gateway run --replace &

Expected Behavior

The gateway should handle connection pooling robustly:

  • Release connections back to the pool after each request
  • Configure appropriate pool limits and timeouts for long-running operation
  • Optionally implement a health check / watchdog that detects a stuck gateway and auto-recovers

Actual Behavior

Gateway hangs silently after ~24h. No automatic recovery. Requires manual kill + restart.

Environment

  • OS: Ubuntu on WSL2 (Windows 11)
  • Hermes Agent: latest (installed via hermes-agent setup)
  • Python: venv under ~/.hermes/hermes-agent/
  • Telegram platform: long polling mode

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions