Skip to content

fix(telegram): reconnect long polling after disconnect#1455

Closed
Alix-007 wants to merge 2 commits intosipeed:mainfrom
Alix-007:pr/issue-216-telegram-reconnect
Closed

fix(telegram): reconnect long polling after disconnect#1455
Alix-007 wants to merge 2 commits intosipeed:mainfrom
Alix-007:pr/issue-216-telegram-reconnect

Conversation

@Alix-007
Copy link
Copy Markdown
Contributor

Summary

  • restart Telegram long polling when the handler or updates stream stops unexpectedly
  • keep the initial startup behavior fail-fast, but add a reconnect loop for runtime disconnects
  • add a regression test covering handler restart after disconnect

Fixes #216

Test plan

  • go test ./pkg/channels/telegram -run TestRunPollingLoop_RestartsAfterHandlerStops -count=1

@mymmrac
Copy link
Copy Markdown
Collaborator

mymmrac commented Mar 13, 2026

@Alix-007 I don't think this functionality is needed as long polling will stop only if context is closed, but in that case we don't need to restart it, so why this functionality is needed?

@Alix-007
Copy link
Copy Markdown
Contributor Author

The reconnect path here is only for runtime disconnects where the updates stream stops while the channel context is still alive. Issue #216 documents that case: the gateway stays marked connected, logs a reconnect message, and then stops receiving Telegram updates until process restart.

So this does not restart after normal shutdown/cancel; runPollingLoop exits immediately once ctx.Err() != nil. It only re-establishes polling when bh.Start() returns with a live context after the updates channel has closed unexpectedly.

I also pushed a small lint-only follow-up and re-ran:

  • go test ./pkg/channels/telegram -run TestRunPollingLoop_RestartsAfterHandlerStops -count=1

@Alix-007
Copy link
Copy Markdown
Contributor Author

Closing this for now.

After re-checking the current implementation and the upstream telego behavior, I do not have enough repository-specific evidence to keep this PR open:

  • picoclaw uses github.com/mymmrac/telego v1.7.0, not go-telegram-bot-api
  • telego's UpdatesViaLongPolling already retries GetUpdates errors internally by default, so ordinary polling/network hiccups do not appear to close the updates channel in the way this PR assumes
  • the current regression test exercises a forced handler/channel-stop path, but it does not demonstrate a real telego failure mode seen in picoclaw itself

Given that, and given the PR is now conflicting with main, I think the right move is to close instead of continuing to maintain a fix without a solid reproducer.

If we get a telego-specific reproducer or logs showing the updates stream really exits while the channel context is still alive, I can reopen this as a narrower follow-up.

@Alix-007 Alix-007 closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: channel go Pull requests that update go code type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram gateway can stop responding after long-poll updates channel closes

2 participants