Skip to content

High CPU usage and connection leak due to IPv6 issues on networks with broken IPv6 connectivity #464

@ShmakovPavel

Description

@ShmakovPavel

TL;DR

mtg (version 2.2.8) causes 90%+ CPU usage and accumulates thousands of ESTABLISHED connections when running on a host where IPv6 is partially unavailable (ICMP works, but specific Telegram IPv6 prefixes are unreachable). The issue persists even after disabling IPv6 via sysctl and ip6tables.

Environment

  • mtg version: 2.2.8 (also reproducible on 2.2.7)
  • Deployment: Docker with --network=host
  • Host OS: Ubuntu 22.04 (VPS provider)
  • Network: IPv6 partially available (server has IPv6, can ping google.com IPv6, but specific Telegram IPv6 prefixes are unreachable)

Config (sanitized)

debug = false
secret = "<YOUR_SECRET>"
bind-to = "0.0.0.0:443"
concurrency = 2000
ad_tag = "<YOUR_TAG>"
tolerate-time-skewness = "10s"
prefer-ip = "prefer-ipv4"
ipv6 = false
ipv6-only = false

[network]
doh-ip = "9.9.9.9"
ipv4-only = true
prefer-ipv4 = true

[network.timeout]
tcp = "5s"
http = "10s"
idle = "1m"

[defense.anti-replay]
enabled = true
max-size = "1mib"
error-rate = 0.001

Symptoms

  1. CPU spikes to 90%+ with only a few dozen active users
  2. Thousands of ESTABLISHED connections from a single IP (Docker host 172.17.0.1)
  3. Persistent IPv6 connection attempts despite all configuration flags:
    {"level":"warn","dc":203,"logger":"proxy","error":"no addresses to call: dial tcp6 [2a0a:f280:203:a:5000::100]:443: connect: cannot assign requested address","message":"cannot dial to telegram"}
  4. ss shows active IPv6 connections even after ip6tables -P OUTPUT DROP and sysctl net.ipv6.conf.all.disable_ipv6=1

What I've tried (none worked)

  • Setting ipv6 = false, ipv4-only = true, prefer-ipv4 = true
  • System-level IPv6 disable: sysctl -w net.ipv6.conf.all.disable_ipv6=1
  • Firewall block: ip6tables -P OUTPUT DROP and ip6tables -P INPUT DROP
  • Environment variables: GODEBUG=netdns=go, MTG_IPV6=false
  • Custom DNS with options inet4

The issue only temporarily resolves after docker restart, but connections gradually accumulate again.

Hypothesis

The issue likely started after commit "Change IP address set priority" (around v2.2.7). Version 2.2.5 appears stable (need confirmation). It seems mtg ignores both system-level and application-level IPv6 disable flags when the host has partial IPv6 connectivity (ICMP works, but specific prefixes are unreachable). This creates a loop of failed connection attempts, leaking file descriptors and consuming CPU.

Expected behavior

When ipv6 = false or ipv4-only = true is set, mtg should never attempt to dial IPv6 addresses, regardless of DNS responses or system capabilities.

Additional context

  • The proxy works fine for actual clients (messages are delivered)
  • The issue is not about client IPs (all traffic goes through Docker NAT)
  • This happens on a specific VPS provider; may affect other providers with similar IPv6 routing

Request

Please investigate why mtg ignores ipv6 = false and ipv4-only = true settings on hosts with partial IPv6 connectivity. The ability to completely disable IPv6 is critical for deployments on networks where IPv6 is unreliable.

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