dgraph-io/badger · error

ErrEOF

ErrEOF

Error message

ErrEOF: End of file

What it means

ErrEOF is a sentinel indicating an attempt to read past the end of a memory-mapped file slice — e.g. memtable replay computes that the next entry's offset+size exceeds the mapped log-file size and returns this error instead of slicing out of bounds. It marks a normal end-of-data boundary during value-log/memtable iteration, and callers break their read loop on it rather than treating it as corruption (contrast io.ErrUnexpectedEOF, which signals a torn final entry).

Source

Thrown at y/y.go:30

	"fmt"
	"hash/crc32"
	"io"
	"math"
	"os"
	"reflect"
	"strconv"
	"sync"
	"time"
	"unsafe"

	"github.com/dgraph-io/badger/v4/pb"
	"github.com/dgraph-io/ristretto/v2/z"
)

var (
	// ErrEOF indicates an end of file when trying to read from a memory mapped file
	// and encountering the end of slice.
	ErrEOF = stderrors.New("ErrEOF: End of file")

	// ErrCommitAfterFinish indicates that write batch commit was called after
	// finish
	ErrCommitAfterFinish = stderrors.New("Batch commit not permitted after finish")
)

type Flags int

const (
	// Sync indicates that O_DSYNC should be set on the underlying file,
	// ensuring that data writes do not return until the data is flushed
	// to disk.
	Sync Flags = 1 << iota
	// ReadOnly opens the underlying file on a read-only basis.
	ReadOnly
)

var (

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Handle it as end-of-stream: break the read loop when errors.Is(err, y.ErrEOF) and finalize normally
  2. Do not log or propagate it as a failure in iteration paths
  3. If it surfaces where a complete entry was expected, treat the file tail as truncated and follow value-log truncation recovery
  4. Ensure custom readers of mmap'd files bounds-check offsets before slicing to avoid the out-of-range condition
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at y/y.go:30 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/08aad230a2f7bbf1. Report an issue: GitHub.