VictoriaMetrics/VictoriaMetrics · warning
cannot flush data to client: %w
Error message
cannot flush data to client: %w
What it means
BufferedWriter.Flush propagates an error from the underlying bufio.Writer.Flush when flushing buffered data to the client fails. If the error is a trivial network error (client disconnected), it is swallowed and nil is returned; otherwise bw.err is set and returned to the caller.
Source
Thrown at lib/bufferedwriter/bufferedwriter.go:87
}
return n, bw.err
}
// Flush flushes bw to the underlying writer.
//
// Connection close errors are ignored to not trigger on them and to not write to logs, but Write method doesn't ignore
// them since it may lead to an unexpected behaviour (see https://github.com/VictoriaMetrics/VictoriaMetrics/pull/8157)
func (bw *Writer) Flush() error {
bw.lock.Lock()
defer bw.lock.Unlock()
if bw.err != nil {
if netutil.IsTrivialNetworkError(bw.err) {
return nil
}
return bw.err
}
if err := bw.bw.Flush(); err != nil {
bw.err = fmt.Errorf("cannot flush data to client: %w", err)
if netutil.IsTrivialNetworkError(err) {
return nil
}
}
return bw.err
}
// Error returns the first occurred error in bw.
func (bw *Writer) Error() error {
bw.lock.Lock()
defer bw.lock.Unlock()
return bw.err
}
View on GitHub (pinned to 5079fb58f1)
Solutions
- Read the wrapped cause; trivial network errors are already handled (nil returned), so only real failures reach you
- Confirm client behavior — reconnects/timeouts on the consumer side are the usual root cause
- Check network stability, proxies, and keep-alive settings between server and client
- Add retry at the application layer if the flushed payload can be regenerated
Example fix
// before
if err := bw.Flush(); err != nil { log.Fatal(err) }
// after
if err := bw.Flush(); err != nil {
if netutil.IsTrivialNetworkError(err) {
return nil // client disconnected — not a server fault
}
return err
} Defensive patterns
Strategy: try-catch
Try / catch
if err := bw.Flush(); err != nil && !netutil.IsTrivialNetworkError(err) {
log.Printf("flush failed: %v", err)
} Prevention
- Treat trivial network errors (disconnects) as non-fatal, as the library already does
- Monitor client disconnect rates rather than treating every flush error as a server bug
- Keep the underlying connection alive with keep-alives/proxy timeouts aligned to buffer flush cadence
When it happens
Trigger: Calling bw.Flush() when the underlying writer (network conn) returns a non-trivial error: broken pipe, connection reset by peer, or disk/socket write failure.
Common situations: HTTP client closed the connection before the buffered response finished; TLS renegotiation failures; container/network interruptions mid-stream.
Related errors
- cannot send %d bytes to client: %w
- cannot read response from %q: %w
- cannot download %q from at %s (remote path %q): %w
- cannot read %q at %s (remote dir %q): %w
- cannot download %q from at %s (remote path %q): %w
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/a81a4afae18d8ded.
Report an issue: GitHub.