{"record":{"id":"816e00c7d17187ca","repo":"crowdsecurity/crowdsec","slug":"error-while-reading-tail-response-w","errorCode":null,"errorMessage":"error while reading tail response: %w","messagePattern":"error while reading tail response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/victorialogs/internal/vlclient/vl_client.go","lineNumber":349,"sourceCode":"\t\tbreak\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tlc.Logger.Warnf(\"bad HTTP response code for tail request: %d\", resp.StatusCode)\n\t\tbody, _ := io.ReadAll(resp.Body)\n\t\tresp.Body.Close()\n\n\t\tif ok := lc.shouldRetry(); !ok {\n\t\t\treturn nil, fmt.Errorf(\"bad HTTP response code: %d: %s: %w\", resp.StatusCode, string(body), err)\n\t\t}\n\t}\n\n\tresponseChan := make(chan *Log)\n\n\tlc.t.Go(func() error {\n\t\t_, _, err = lc.readResponse(ctx, resp, responseChan)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error while reading tail response: %w\", err)\n\t\t}\n\n\t\treturn nil\n\t})\n\n\treturn responseChan, nil\n}\n\n// QueryRange queries the logs\n// See: https://docs.victoriametrics.com/victorialogs/querying/#querying-logs\nfunc (lc *VLClient) QueryRange(ctx context.Context, infinite bool) chan *Log {\n\tt := time.Now().Add(-1 * lc.config.Since)\n\tu := lc.getURLFor(\"select/logsql/query\", map[string]string{\n\t\t\"query\": lc.config.Query,\n\t\t\"start\": t.Format(time.RFC3339Nano),\n\t\t\"limit\": strconv.Itoa(lc.config.Limit),\n\t})\n","sourceCodeStart":331,"sourceCodeEnd":367,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/victorialogs/internal/vlclient/vl_client.go#L331-L367","documentation":"The background goroutine that streams the tail HTTP response body into the channel hit an error while decoding server-sent-events/NDJSON from VictoriaLogs. This runs inside the tomb, so the failure kills the acquisition goroutine group rather than returning to the caller.","triggerScenarios":"`readResponse` fails mid-stream: the tail connection is dropped by the server or a proxy, a read timeout fires, the body contains malformed/undecodable log entries, or ctx is canceled causing the response read to abort with an unexpected error.","commonSituations":"A load balancer with a short idle timeout kills long-lived tail connections; network interruption during live tailing; VictoriaLogs crashes mid-response; incompatible VictoriaLogs version emitting a payload shape this client cannot decode.","solutions":["Check the wrapped inner error: if it is `unexpected EOF`/`connection reset`, suspect intermediaries and raise their idle/proxy timeouts.","Verify the VictoriaLogs version is compatible; upgrade the datasource or crowdsec if the payload format changed.","Ensure stable network between crowdsec and VictoriaLogs for long-lived streaming connections.","If timeouts are the cause, adjust client timeout settings for the streaming request.","Restart crowdsec; in TAIL_MODE the stream must be re-established."],"exampleFix":"// nginx-style intermediary\n// before\nproxy_read_timeout 30s;\n// after\nproxy_read_timeout 3600s;  # keep long-lived tail streams alive","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// in the tomb goroutine\nif err := readResponse(ctx, resp, ch); err != nil {\n    if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) {\n        return nil // clean end / shutdown\n    }\n    return fmt.Errorf(\"error while reading tail response: %w\", err)\n}","preventionTips":["Raise load-balancer/proxy idle timeouts for SSE streams","Keep VictoriaLogs and crowdsec versions compatible","Monitor connection stability for long-lived tails","Use TCP keepalives on the path between services"],"tags":["network","streaming","victorialogs","io"],"backgroundTag":"broken-pipe","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"}