dgraph-io/badger · error
ErrCommitAfterFinish
ErrCommitAfterFinish
Error message
Batch commit not permitted after finish
What it means
ErrCommitAfterFinish is a sentinel guard returned by WriteBatch.Commit/Flush (batch.go:197) when commit is attempted after wb.finished is true — i.e. the batch was already flushed/finished (or cancelled) and then committed again. The batch's entry slice and throttled writes are no longer valid after finish, so the guard prevents double-commit and use-after-finish misuse. The input at fault is the caller's sequencing of Flush/Cancel and Commit calls on the same WriteBatch.
Source
Thrown at y/y.go:34
"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 (
// This is O_DSYNC (datasync) on platforms that support it -- see file_unix.go
datasyncFileFlag = 0x0
// CastagnoliCrcTable is a CRC32 polynomial tableView on GitHub (pinned to 2a001d466f)
Solutions
- Check the error explicitly with errors.Is(err, y.ErrCommitAfterFinish) and ignore or log it — a repeated Flush is usually harmless idempotent cleanup
- Fix the calling code so Flush/Cancel is called exactly once per WriteBatch; do not reuse a batch after finishing
- Guard concurrent users of a shared WriteBatch with a mutex or create a fresh batch per goroutine
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at y/y.go:34 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/82fee729efde3ab9.
Report an issue: GitHub.