{"record":{"id":"b53185dbd7e194e2","repo":"crowdsecurity/crowdsec","slug":"error-querying-range-w","errorCode":null,"errorMessage":"error querying range: %w","messagePattern":"error querying range: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go","lineNumber":139,"sourceCode":"\t\tticker.Reset(lc.currentTickerInterval)\n\t}\n}\n\nfunc (lc *LokiClient) queryRange(ctx context.Context, uri string, c chan *LokiQueryRangeResponse, infinite bool) error {\n\tlc.currentTickerInterval = 100 * time.Millisecond\n\tticker := time.NewTicker(lc.currentTickerInterval)\n\tdefer ticker.Stop()\n\tfor {\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tcase <-lc.t.Dying():\n\t\t\treturn lc.t.Err()\n\t\tcase <-ticker.C:\n\t\t\tresp, err := lc.Get(ctx, uri)\n\t\t\tif err != nil {\n\t\t\t\tif ok := lc.shouldRetry(); !ok {\n\t\t\t\t\treturn fmt.Errorf(\"error querying range: %w\", err)\n\t\t\t\t}\n\t\t\t\tlc.increaseTicker(ticker)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif resp.StatusCode != http.StatusOK {\n\t\t\t\tlc.Logger.Warnf(\"bad HTTP response code for query range: %d\", resp.StatusCode)\n\t\t\t\tbody, _ := io.ReadAll(resp.Body)\n\t\t\t\tresp.Body.Close()\n\t\t\t\tif ok := lc.shouldRetry(); !ok {\n\t\t\t\t\treturn fmt.Errorf(\"bad HTTP response code: %d: %s: %w\", resp.StatusCode, string(body), err)\n\t\t\t\t}\n\t\t\t\tlc.increaseTicker(ticker)\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tvar lq LokiQueryRangeResponse\n\t\t\tif err := json.NewDecoder(resp.Body).Decode(&lq); err != nil {","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/loki/internal/lokiclient/loki_client.go#L121-L157","documentation":"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.","triggerScenarios":"Loki unreachable (connection refused, DNS failure), TLS errors, or context cancellation during Get, once retries are exhausted.","commonSituations":"Loki container down or restarted; wrong port in the DSN; network partitions in k8s environments.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// before starting, probe the endpoint:\n// resp, err := http.Get(\"http://loki:3100/ready\")","typeGuard":null,"tryCatchPattern":"if err := runQueryRange(ctx); err != nil {\n    if errors.Is(err, context.Canceled) { return }\n    log.Errorf(\"loki query failed: %v; will re-run datasource\", err)\n    // backoff and retry the whole datasource start\n}","preventionTips":["Monitor Loki readiness (/ready) before starting the datasource","Use stable DNS names/Service endpoints for Loki","Avoid restarting Loki while datasources are polling"],"tags":["loki","network","http"],"backgroundTag":"api-request-failed","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}