micro/go-micro · error
poll request failed: %w
Error message
poll request failed: %w
What it means
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).
Source
Thrown at ai/atlascloud/atlascloud.go:1013
return nil, err
}
if result != nil {
return result, nil
}
}
}
}
func (p *Provider) pollPrediction(ctx context.Context, url string) (*ai.ImageResponse, error) {
httpReq, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, err
}
httpReq.Header.Set("Authorization", "Bearer "+p.opts.APIKey)
httpResp, err := http.DefaultClient.Do(httpReq)
if err != nil {
return nil, fmt.Errorf("poll request failed: %w", err)
}
defer httpResp.Body.Close()
body, _ := io.ReadAll(httpResp.Body)
var pollResp struct {
Data struct {
Status string `json:"status"`
Outputs []string `json:"outputs"`
Error string `json:"error"`
} `json:"data"`
}
if err := json.Unmarshal(body, &pollResp); err != nil {
return nil, fmt.Errorf("failed to parse poll response: %w", err)
}
switch pollResp.Data.Status {
case "completed":View on GitHub (pinned to 24529f1404)
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.
Example fix
// before
if err != nil {
return nil, fmt.Errorf("poll request failed: %w", err)
}
// after
if err != nil {
if errors.Is(err, context.Canceled) {
return nil, fmt.Errorf("poll request failed: %w", err)
}
if consecutiveFails++; consecutiveFails <= 5 {
continue // tolerate transient poll failures
}
return nil, fmt.Errorf("poll request failed: %w", err)
} Defensive patterns
Strategy: retry
Try / catch
img, err := provider.GenerateImage(ctx, req)
if err != nil {
if errors.Is(err, context.Canceled) {
return err // caller gave up; do not retry
}
if strings.Contains(err.Error(), "poll request failed") {
var nerr net.Error
if errors.As(err, &nerr) && nerr.Timeout() {
// resume polling with the same prediction flow or retry
}
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- API request failed: %w
- API error: nil response
- failed request
- failed to parse response: %w
- no response from API
AI-assisted analysis of micro/go-micro@24529f1404 (2026-09-01).
Data as JSON: /api/errors/74adccf4d8975613.
Report an issue: GitHub.