bufio.ErrBufferFull
GoERRORNotableIO

bufio: buffer full

Quick Answer

Create the bufio.Reader with a larger buffer using bufio.NewReaderSize to handle longer lines.

What this means

Returned by bufio.Reader when a single token or line is too large to fit in the reader buffer. Increase the buffer size or use ReadBytes for large lines.

Why it happens
  1. 1Line or token exceeds the default 4096-byte bufio buffer
  2. 2Large binary protocol frame read with ReadSlice

Fix

Increase buffer size

Increase buffer size
r := bufio.NewReaderSize(src, 1<<20) // 1 MB
line, err := r.ReadString('
')

Why this works

A larger buffer allows ReadString to hold the entire line before returning.

Code examples
Detectgo
_, err := r.ReadSlice('
')
if errors.Is(err, bufio.ErrBufferFull) {
    fmt.Println("line too long for buffer")
}
Larger readergo
r := bufio.NewReaderSize(conn, 65536)
line, _ := r.ReadString('
')
ReadBytes fallbackgo
// ReadBytes grows internally if needed
line, err := r.ReadBytes('
')
Sources
Official documentation ↗

Go standard library

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Go errors