{"record":{"id":"c11de09337573e26","repo":"chenhg5/cc-connect","slug":"telegram-connect-failed-w","errorCode":null,"errorMessage":"telegram: connect failed: %w","messagePattern":"telegram: connect failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/telegram/telegram.go","lineNumber":368,"sourceCode":"\t\tcase <-ctx.Done():\n\t\t\ttimer.Stop()\n\t\t\treturn\n\t\tcase <-timer.C():\n\t\t}\n\t}\n}\n\nfunc (p *Platform) runConnection(ctx context.Context) error {\n\tfactory := p.getNewBot()\n\tb, me, startPoll, err := factory(p.token, p.processUpdate, p.httpClient)\n\tif err != nil {\n\t\tcause := retryCauseInitialConnectFailure\n\t\tif p.hasEverConnected() {\n\t\t\tcause = retryCauseReconnectFailure\n\t\t}\n\t\treturn &retryLoopError{\n\t\t\tcause: cause,\n\t\t\terr:   fmt.Errorf(\"telegram: connect failed: %w\", err),\n\t\t}\n\t}\n\tif ctx.Err() != nil || p.isStopping() {\n\t\treturn nil\n\t}\n\n\tgen, ok := p.publishBot(b, me)\n\tif !ok {\n\t\treturn nil\n\t}\n\n\tslog.Info(\"telegram: connected\", \"bot\", me.Username)\n\tp.emitReady(gen)\n\n\t// Start polling — blocks until ctx is cancelled or connection drops.\n\tstartPoll(ctx)\n\n\tp.clearBot(gen, b)","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/telegram/telegram.go#L350-L386","documentation":"runConnection wraps any failure establishing the Telegram long-poll connection (getUpdates/bot setup) into a retryLoopError tagged as initial-connect or reconnect failure depending on whether the platform has ever connected. The wrapped err carries the underlying cause.","triggerScenarios":"The polling loop's connection attempt fails — bot creation error, getMe failure, or first getUpdates error — before or after a previously successful connection (which switches the retry cause from initial to reconnect).","commonSituations":"Network flap while the daemon runs; Telegram returning 409 Conflict because another poller instance holds a long-poll; token revoked mid-run; DNS failure.","solutions":["Ensure no other process/bot instance is polling the same token (409 Conflict)","Check host network connectivity and proxy settings","Rely on/configure the retry backoff loop; inspect the wrapped cause for the root error","Re-verify the token if 401s persist"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := plat.Start(handler); err != nil {\n    var rle *RetryLoopError\n    if errors.As(err, &rle) {\n        slog.Error(\"telegram connect loop ended\", \"cause\", rle.Cause, \"err\", rle.Err)\n    }\n    return err\n}","preventionTips":["Run a single poller per bot token (avoids 409 conflicts)","Monitor host network stability; use a proxy with sane timeouts","Let the built-in retry/backoff loop handle transient failures","Alert on repeated reconnect failures rather than crashing"],"tags":["telegram","connection","retry","network"],"backgroundTag":"http-request-failed","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"}