{"record":{"id":"127deacf69be4e52","repo":"chenhg5/cc-connect","slug":"telegram-connection-lost","errorCode":null,"errorMessage":"telegram: connection lost","messagePattern":"telegram: connection lost","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"platform/telegram/telegram.go","lineNumber":720,"sourceCode":"\tp.markReady()\n\n\tif handler != nil {\n\t\thandler.OnPlatformReady(p)\n\t}\n}\n\nfunc (p *Platform) clearBot(gen uint64, b telegramBot) {\n\tnotify := false\n\tp.mu.Lock()\n\tif p.bot == b && p.generation == gen {\n\t\tp.bot = nil\n\t\tp.selfUser = nil\n\t\tnotify = !p.stopping\n\t}\n\tp.mu.Unlock()\n\n\tif notify {\n\t\tp.notifyUnavailable(fmt.Errorf(\"telegram: connection lost\"))\n\t}\n}\n\nfunc (p *Platform) connectedBot(action string) (telegramBot, error) {\n\tp.mu.RLock()\n\tdefer p.mu.RUnlock()\n\tif p.bot == nil {\n\t\treturn nil, fmt.Errorf(\"telegram: %s: bot not connected\", action)\n\t}\n\treturn p.bot, nil\n}\n\nfunc (p *Platform) botUsername() string {\n\tp.mu.RLock()\n\tdefer p.mu.RUnlock()\n\tif p.selfUser == nil {\n\t\treturn \"\"\n\t}","sourceCodeStart":702,"sourceCodeEnd":738,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L702-L738","documentation":"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.","triggerScenarios":"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.","commonSituations":"Network outage on the host; Telegram API unreachable for an extended period; connection killed by a NAT/firewall idle timeout during long polls.","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"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// subscribe to unavailability notifications\nonUnavailable := func(err error) {\n    if err != nil && err.Error() == \"telegram: connection lost\" {\n        slog.Warn(\"telegram offline; awaiting auto-reconnect\")\n    }\n}","preventionTips":["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"],"tags":["telegram","connection","disconnect","resilience"],"backgroundTag":"connection-lost","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}