chenhg5/cc-connect · error

poll failed: %w

Error message

poll failed: %w

What it means

This wraps a transport-level failure of the registration 'poll' call, which the flow issues repeatedly to check whether the user completed QR authorization. Any HTTP/network error during polling aborts the onboarding flow with this wrapped cause.

Source

Thrown at cmd/cc-connect/feishu.go:600

	interval := beginRes.Interval
	if interval <= 0 {
		interval = 5
	}
	expireIn := beginRes.ExpireIn
	if expireIn <= 0 {
		expireIn = opts.TimeoutSeconds
	}

	timeoutAt := time.Now().Add(time.Duration(expireIn) * time.Second)
	if limitByFlag := time.Now().Add(time.Duration(opts.TimeoutSeconds) * time.Second); limitByFlag.Before(timeoutAt) {
		timeoutAt = limitByFlag
	}

	platformType := "feishu"
	for time.Now().Before(timeoutAt) {
		var pollRes registrationPollResponse
		if err := client.registrationCall("poll", map[string]string{"device_code": beginRes.DeviceCode}, &pollRes); err != nil {
			return nil, fmt.Errorf("poll failed: %w", err)
		}

		tenantBrand := strings.ToLower(strings.TrimSpace(pollRes.UserInfo.TenantBrand))
		if tenantBrand == "lark" {
			platformType = "lark"
			if client.baseURL != accountsLarkBaseURL {
				client.baseURL = accountsLarkBaseURL
				if opts.Debug {
					fmt.Fprintln(os.Stderr, "[debug] tenant brand detected as lark, switched onboarding domain")
				}
				continue
			}
		}

		if pollRes.ClientID != "" && pollRes.ClientSecret != "" {
			return &registrationFlowResult{
				AppID:       pollRes.ClientID,
				AppSecret:   pollRes.ClientSecret,

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Re-run the setup flow; the device-code session is not resumable after a fatal poll error.
  2. Check network stability and proxy/firewall idle timeouts (long-poll connections may be killed); disable aggressive proxy connection reaping if applicable.
  3. Inspect debug output for the exact HTTP status/error of the failing poll request.
  4. Prevent sleep/network switches during the QR scan window, then retry.

Example fix

// before
// network drops mid-poll → poll failed: Post ...: connection reset by peer
// after
$ cc-connect setup feishu   # retry on stable network
Defensive patterns

Strategy: retry

Validate before calling

// preflight: ensure endpoint is reachable and stable before the long poll loop
if _, err := net.LookupTimeout(host); err != nil { return err }

Try / catch

for attempts := 0; attempts < 3; attempts++ {
	err := runRegistrationFlow(...)
	if err == nil || !isNetErr(err) { return err }
	time.Sleep(backoff(attempts))
}

Prevention

When it happens

Trigger: Inside the polling loop, client.registrationCall("poll", {device_code}, &pollRes) returns a non-nil error — connection drop, timeout, DNS failure, or an HTTP status treated as fatal inside registrationCall — while time.Now().Before(timeoutAt) still holds.

Common situations: Losing network mid-scan (mobile user switching Wi-Fi/cellular); the long-running poll loop crossing a proxy idle timeout; registration service flakiness during the wait window; laptop sleep/resume breaking the connection.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/424e027a799c8a1d. Report an issue: GitHub.