Skip to content

fix(telegram): keep the long poll connected and heal short blips - #37

Merged
morningstarnasser merged 1 commit into
mainfrom
fix/telegram-poll-resilience-20261125
Nov 25, 2026
Merged

morningstarnasser merged 1 commit into
mainfrom
fix/telegram-poll-resilience-20261125

Conversation

@morningstarnasser

Copy link
Copy Markdown
Contributor

What

The Telegram long poll now uses one kept-alive connection with TCP keepalive probes, and it retries getUpdates itself for failures that cannot have changed anything.

Why

Nine days of a deployed instance's event log: 150 read timeouts, 37 connection resets, 73 DNS failures and 127 gateway errors on getUpdates. Nearly all were single events that the next poll survived. Each poll opened a new TCP and TLS connection and did its own DNS lookup, and each failure was written as channel.error.

Behaviour

  • Transient failure (timeout, reset, DNS, 5xx, short 429): retried with the unchanged offset on a fresh connection for at most 20 s. Healed blips write nothing.
  • Second consecutive read timeout, lasting outage, or any rejection (401, 409, other 4xx): raised as before and recorded by poll_all.
  • Sends are untouched and keep their single attempt. No kernel module is changed.

Evidence

  • 3605 passed, 2 skipped; red team 277/277; hygiene check passed; OSV on all four locks: no issues.
  • Target tests run twice in a row, then the full suite once.
  • Real wire, no bot token: on macOS and on an ARM64 Linux host, repeated requests used one connection (about 25 ms each instead of about 440 ms for the first) and the socket carried the keepalive settings. A rejected token raised at once with zero retries and no token in the message.

Not yet shown: the effect on the daily error count. That needs several days of the deployed instance.

The collected test count moves from 3583 to 3607, so the README, CLAUDE.md and site counters are updated in the same commit.

🤖 Generated with Claude Code

Measured on a deployed instance over nine days: 150 read timeouts, 37
connection resets, 73 DNS failures and 127 gateway errors on getUpdates,
nearly all single events that the next poll survived. Every poll opened a
new TCP and TLS connection and resolved the name again, and every failure
was recorded as channel.error.

- Poll over one kept-alive session with TCP keepalive probes (15 s idle,
  3 probes 5 s apart), so a dropped route surfaces after about 30 s
  instead of at the 60 s read deadline. Connecting gets its own 10 s
  deadline.
- Retry getUpdates with the unchanged offset for transient failures
  (timeout, reset, DNS, 5xx, short 429) for at most 20 s on a fresh
  connection. A second consecutive read timeout, a lasting outage and any
  rejection (401, 409, other 4xx) are raised as before.

What this changes for an operator: a blip that heals within the window no
longer writes channel.error. Silence stays bounded, so a cut-off channel
is still reported. Sends are untouched and keep their single attempt.
No kernel module is involved.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@morningstarnasser
morningstarnasser merged commit 5d6ab78 into main Nov 25, 2026
4 checks passed
@morningstarnasser
morningstarnasser deleted the fix/telegram-poll-resilience-20261125 branch November 25, 2026 17:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant