{"record":{"id":"74adccf4d8975613","repo":"micro/go-micro","slug":"poll-request-failed-w","errorCode":null,"errorMessage":"poll request failed: %w","messagePattern":"poll request failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ai/atlascloud/atlascloud.go","lineNumber":1013,"sourceCode":"\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif result != nil {\n\t\t\t\treturn result, nil\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunc (p *Provider) pollPrediction(ctx context.Context, url string) (*ai.ImageResponse, error) {\n\thttpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\thttpReq.Header.Set(\"Authorization\", \"Bearer \"+p.opts.APIKey)\n\n\thttpResp, err := http.DefaultClient.Do(httpReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"poll request failed: %w\", err)\n\t}\n\tdefer httpResp.Body.Close()\n\n\tbody, _ := io.ReadAll(httpResp.Body)\n\n\tvar pollResp struct {\n\t\tData struct {\n\t\t\tStatus  string   `json:\"status\"`\n\t\t\tOutputs []string `json:\"outputs\"`\n\t\t\tError   string   `json:\"error\"`\n\t\t} `json:\"data\"`\n\t}\n\tif err := json.Unmarshal(body, &pollResp); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse poll response: %w\", err)\n\t}\n\n\tswitch pollResp.Data.Status {\n\tcase \"completed\":","sourceCodeStart":995,"sourceCodeEnd":1031,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/ai/atlascloud/atlascloud.go#L995-L1031","documentation":"pollPrediction wraps transport errors from http.DefaultClient.Do when polling GET /api/v1/model/prediction/{id} for image-generation status. A single failed poll aborts the whole GenerateImage flow, even though prediction polling is inherently retry-friendly. The wrapped error preserves the underlying cause (timeout, reset, cancellation).","triggerScenarios":"Any poll tick's http.Do fails: transient connection reset, ctx cancelled (e.g. caller gave up or a deadline set on the polling ctx expired), DNS blip, or the prediction endpoint being temporarily unavailable while the prediction is still processing.","commonSituations":"Long-running image predictions outliving the client timeout on individual polls, network instability during a 2-second-interval poll loop, caller cancelling the context after losing interest, or prediction ID endpoint returning intermittent 5xx at transport level.","solutions":["Make poll failures retryable: tolerate N consecutive poll errors before aborting, instead of returning on the first failure.","Check errors.Is(err, context.Canceled)/DeadlineExceeded to distinguish caller cancellation from real network faults.","Increase per-request timeout or keepalive settings if polls time out under load.","Verify the BaseURL prediction path is stable/reachable; add exponential backoff between retries."],"exampleFix":"// before\nif err != nil {\n    return nil, fmt.Errorf(\"poll request failed: %w\", err)\n}\n// after\nif err != nil {\n    if errors.Is(err, context.Canceled) {\n        return nil, fmt.Errorf(\"poll request failed: %w\", err)\n    }\n    if consecutiveFails++; consecutiveFails <= 5 {\n        continue // tolerate transient poll failures\n    }\n    return nil, fmt.Errorf(\"poll request failed: %w\", err)\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"img, err := provider.GenerateImage(ctx, req)\nif err != nil {\n    if errors.Is(err, context.Canceled) {\n        return err // caller gave up; do not retry\n    }\n    if strings.Contains(err.Error(), \"poll request failed\") {\n        var nerr net.Error\n        if errors.As(err, &nerr) && nerr.Timeout() {\n            // resume polling with the same prediction flow or retry\n        }\n    }\n    return err\n}","preventionTips":["Treat individual poll failures as transient; only abort after several consecutive failures.","Size the context deadline to cover the full polling window (many 2s ticks), not a single request.","Never cancel the polling context prematurely if the image is still needed.","Add backoff between polls and jitter to avoid hammering a struggling endpoint."],"tags":["network","polling","retry","go","atlascloud"],"backgroundTag":"poll-request-transport-failed","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}