crowdsecurity/crowdsec · error
error querying range: %w
Error message
error querying range: %w
What it means
In queryRange's polling loop, lc.Get (HTTP GET to Loki's query_range endpoint) failed, and after the retry policy (shouldRetry) determined no more retries were allowed, the underlying error is wrapped and returned.
Source
Thrown at pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go:139
ticker.Reset(lc.currentTickerInterval)
}
}
func (lc *LokiClient) queryRange(ctx context.Context, uri string, c chan *LokiQueryRangeResponse, infinite bool) error {
lc.currentTickerInterval = 100 * time.Millisecond
ticker := time.NewTicker(lc.currentTickerInterval)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return ctx.Err()
case <-lc.t.Dying():
return lc.t.Err()
case <-ticker.C:
resp, err := lc.Get(ctx, uri)
if err != nil {
if ok := lc.shouldRetry(); !ok {
return fmt.Errorf("error querying range: %w", err)
}
lc.increaseTicker(ticker)
continue
}
if resp.StatusCode != http.StatusOK {
lc.Logger.Warnf("bad HTTP response code for query range: %d", resp.StatusCode)
body, _ := io.ReadAll(resp.Body)
resp.Body.Close()
if ok := lc.shouldRetry(); !ok {
return fmt.Errorf("bad HTTP response code: %d: %s: %w", resp.StatusCode, string(body), err)
}
lc.increaseTicker(ticker)
continue
}
var lq LokiQueryRangeResponse
if err := json.NewDecoder(resp.Body).Decode(&lq); err != nil {View on GitHub (pinned to 909b515798)
Solutions
- Check Loki is reachable: curl the query_range URL from the crowdsec host
- Fix host/port/scheme in the loki:// DSN
- Increase tolerance by checking shouldRetry/backoff behavior; restart the datasource
- Check TLS configuration and CA trust if using https
Defensive patterns
Strategy: try-catch
Validate before calling
// before starting, probe the endpoint:
// resp, err := http.Get("http://loki:3100/ready") Try / catch
if err := runQueryRange(ctx); err != nil {
if errors.Is(err, context.Canceled) { return }
log.Errorf("loki query failed: %v; will re-run datasource", err)
// backoff and retry the whole datasource start
} Prevention
- Monitor Loki readiness (/ready) before starting the datasource
- Use stable DNS names/Service endpoints for Loki
- Avoid restarting Loki while datasources are polling
When it happens
Trigger: Loki unreachable (connection refused, DNS failure), TLS errors, or context cancellation during Get, once retries are exhausted.
Common situations: Loki container down or restarted; wrong port in the DSN; network partitions in k8s environments.
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
- error connecting to websocket
- bad HTTP response code: %d: %s: %w
- error decoding Loki response: %w
- websocket error: %w
- querying range: %w
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/b53185dbd7e194e2.
Report an issue: GitHub.