Skip to content

Telegram polling fails when DoH returns same IP as system DNS #14520

@tegongxia-cpu

Description

@tegongxia-cpu

Bug Description

Telegram Bot API polling fails intermittently due to a bug in `telegram_network.py` `discover_fallback_ips()` function.

Root Cause

In `gateway/platforms/telegram_network.py` around line 210, the code excludes system DNS IPs from the fallback candidates:

if ip not in seen and ip not in system_ips:

When DoH (DNS-over-HTTPS) returns the same IP as the system resolver, that IP is incorrectly filtered out. In many network environments, the system DNS result is actually the most reliable path to api.telegram.org, so excluding it causes fallback to hardcoded IPs that may not be routable.

Fix

Remove the system_ips exclusion, keeping only the deduplication logic:

# Before
if ip not in seen and ip not in system_ips:

# After  
if ip not in seen:

Environment

  • Affected: Multiple users in regions with unstable routing to Telegram servers
  • Not region-specific — can occur whenever DoH and system DNS return overlapping results

Verification

After the fix, the connection uses the correct reachable IP (verified via lsof: `TCP -> 149.154.166.110:443 ESTABLISHED`) instead of falling back to an unreachable hardcoded IP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High — major feature broken, no workaroundcomp/gatewayGateway runner, session dispatch, deliveryplatform/telegramTelegram bot adaptertype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions