chenhg5/cc-connect · warning
telegram: connection lost
Error message
telegram: connection lost
What it means
clearBot() tears down the currently connected bot (setting p.bot and p.selfUser to nil) and, unless the platform is intentionally stopping, notifies unavailability with the fixed error "telegram: connection lost". It signals that the platform can no longer send/receive until a reconnect succeeds.
Source
Thrown at platform/telegram/telegram.go:720
p.markReady()
if handler != nil {
handler.OnPlatformReady(p)
}
}
func (p *Platform) clearBot(gen uint64, b telegramBot) {
notify := false
p.mu.Lock()
if p.bot == b && p.generation == gen {
p.bot = nil
p.selfUser = nil
notify = !p.stopping
}
p.mu.Unlock()
if notify {
p.notifyUnavailable(fmt.Errorf("telegram: connection lost"))
}
}
func (p *Platform) connectedBot(action string) (telegramBot, error) {
p.mu.RLock()
defer p.mu.RUnlock()
if p.bot == nil {
return nil, fmt.Errorf("telegram: %s: bot not connected", action)
}
return p.bot, nil
}
func (p *Platform) botUsername() string {
p.mu.RLock()
defer p.mu.RUnlock()
if p.selfUser == nil {
return ""
}View on GitHub (pinned to 4000b2338a)
Solutions
- Wait for the retry loop to reconnect — the platform auto-recovers
- Check host internet connectivity and firewall/NAT idle-timeout settings
- Increase any keepalive or lower proxy idle timeouts if dropouts are frequent
- Handle the unavailability notification upstream to show the bot as offline
Defensive patterns
Strategy: retry
Try / catch
// subscribe to unavailability notifications
onUnavailable := func(err error) {
if err != nil && err.Error() == "telegram: connection lost" {
slog.Warn("telegram offline; awaiting auto-reconnect")
}
} Prevention
- Rely on the auto-reconnect loop; avoid sending while unavailable
- Configure NAT/firewall idle timeouts longer than the 59s long-poll
- Monitor connectivity to api.telegram.org
- Queue outbound messages during outages and flush on reconnect
When it happens
Trigger: The connection loop detects a lost connection (polling error, repeated failures, context cancellation not due to Stop) and calls clearBot to drop the bot; the notification is only sent when not stopping.
Common situations: Network outage on the host; Telegram API unreachable for an extended period; connection killed by a NAT/firewall idle timeout during long polls.
Related errors
- telegram: connect failed: %w
- telegram: %s: bot not connected
- connect permission bridge: %w
- reasonix: POST %s: %w
- qq: ws connect failed (%s): %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/127deacf69be4e52.
Report an issue: GitHub.