VictoriaMetrics/VictoriaMetrics · error
%s
Error message
%s
What it means
httpserver.Errorf writes a formatted error to the client and logs it with remote address and request URI. If response headers were already sent (responseWriterWithAbort.sentHeaders), it cannot send a status code, so it writes the (unescaped to wire, HTML-escaped variant when streaming) message into the body and aborts the connection to break keep-alive — the surfaced message is just the formatted errStr. Otherwise it calls http.Error with a status extracted from any ErrorWithStatusCode argument (default 400).
Source
Thrown at lib/httpserver/httpserver.go:782
for _, arg := range args {
if err, ok := arg.(error); ok && errors.As(err, &esc) {
statusCode = esc.StatusCode
break
}
}
if rwa, ok := w.(*responseWriterWithAbort); ok && rwa.sentHeaders {
// HTTP status code has been already sent to client, so it cannot be sent again.
// Just write errStr to the response and abort the client connection, so the client could notice the error.
//
// HTML-escape the errStr in order to protect from possible XSS, since the errStr may contain user input.
errStrEscaped := html.EscapeString(errStr)
fmt.Fprintf(w, "\n%s\n", errStrEscaped)
rwa.abort()
return
}
http.Error(w, errStr, statusCode)
}
// logHTTPError logs the errStr with the client remote address and the request URI obtained from r.
func logHTTPError(r *http.Request, errStr string) {
remoteAddr := GetQuotedRemoteAddr(r)
requestURI := GetRequestURI(r)
errStr = fmt.Sprintf("remoteAddr: %s; requestURI: %s; %s", remoteAddr, requestURI, errStr)
logger.WarnfSkipframes(2, "%s", errStr)
}
// ErrorWithStatusCode is error with HTTP status code.
//
// The given StatusCode is sent to client when the error is passed to Errorf.
type ErrorWithStatusCode struct {
Err error
StatusCode int
}
View on GitHub (pinned to 5079fb58f1)
Solutions
- Read the response body / server log line (remoteAddr, requestURI, message) to identify the actual handler error
- Fix the client request that triggered the handler error (correct path, query params, payload)
- If the connection is being aborted mid-response, check server logs for the underlying cause rather than the truncated client message
Defensive patterns
Strategy: try-catch
Validate before calling
// validate request before hitting the server
if !strings.HasPrefix(path, "/api/v1/") && !knownPaths[path] {
return fmt.Errorf("path %q is not supported; check server logs via Errorf output", path)
} Type guard
func isHTTPServerError(err error) (*httpserver.ErrorWithStatusCode, bool) {
var esc *httpserver.ErrorWithStatusCode
ok := errors.As(err, &esc)
return esc, ok
} Try / catch
resp, err := doRequest(req)
if err != nil {
return err
}
if resp.StatusCode >= 400 {
body, _ := io.ReadAll(io.LimitReader(resp.Body, 4096))
return fmt.Errorf("server rejected request (status %d): %s", resp.StatusCode, strings.TrimSpace(string(body)))
}
// mid-stream abort case: headers already sent, connection closed
if resp.Header.Get("Connection") == "close" && bodyTruncated {
return fmt.Errorf("response aborted mid-stream; check server log for Errorf message")
} Prevention
- Check server logs (remoteAddr + requestURI prefix) to find the failing handler
- Handle ErrorWithStatusCode status codes (e.g. 503) with retry on the client
- Do not rely on the body of aborted responses — the error text may be HTML-escaped or truncated
- Validate paths and query parameters against the API surface before sending
When it happens
Trigger: Handlers calling Errorf(w, r, format, args...) — e.g. unsupported paths, invalid query params, insert/query failures — including when the status code was already committed and the connection must be aborted mid-response.
Common situations: Clients requesting unknown paths or malformed queries; errors occurring mid-stream after headers were sent (client sees truncated body plus aborted keep-alive connection); an ErrorWithStatusCode in args propagating 503s from the insert limiter.
Related errors
- cannot perform http request to %q: %w
- cannot read response from %q: %w
- cannot get credentials from %s: %w
- cannot fetch %q: %w
- cannot gracefully shutdown http server at %q in %.3fs; proba
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/87095911ed1684d6.
Report an issue: GitHub.