fix(telegram): auto-restart polling on post-startup 409 conflicts#1
Merged
Conversation
The previous start() only retried 409s during the initial connect. Once
onStart fired, any subsequent 409 (stale getUpdates from another process,
old deployment, or webhook still set) crashed polling silently — the
.catch's reject() was a no-op because the wrapper promise had already
resolved. Result: bot replies once, then dies.
- deleteWebhook({ drop_pending_updates: true }) before polling so any
conflicting consumer is bumped instead of holding 409 forever.
- Track started state and schedule an auto-restart on post-startup
failures, with delay tuned to outlast Telegram's ~50s long-poll.
- Suppress restart when stop() is called.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
start()'s.catchonly handled 409s during initial connect. AfteronStartfired, any post-startup 409 hit a no-opreject()(wrapper promise already resolved) and polling crashed with no restart.deleteWebhook({ drop_pending_updates: true })before polling — forcibly bumps any stale getUpdates consumer holding the conflict.startedstate and auto-restarts polling on post-startup runtime errors with a 60s delay (outlasts Telegram's ~50s long-poll).stop()sets a guard so intentional shutdown doesn't loop.Test plan
telegram.bot_startedlog on bootTELEGRAM_BOT_TOKEN— fix logstelegram.restart_scheduledso it's observablestop()on SIGTERM does not trigger a restart loophttps://claude.ai/code/session_01X7wX5mMrbR83iWEv4mg8aq
Generated by Claude Code