{"record":{"id":"82fee729efde3ab9","repo":"dgraph-io/badger","slug":"errcommitafterfinish","errorCode":"ErrCommitAfterFinish","errorMessage":"Batch commit not permitted after finish","messagePattern":"Batch commit not permitted after finish","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"y/y.go","lineNumber":34,"sourceCode":"\t\"os\"\n\t\"reflect\"\n\t\"strconv\"\n\t\"sync\"\n\t\"time\"\n\t\"unsafe\"\n\n\t\"github.com/dgraph-io/badger/v4/pb\"\n\t\"github.com/dgraph-io/ristretto/v2/z\"\n)\n\nvar (\n\t// ErrEOF indicates an end of file when trying to read from a memory mapped file\n\t// and encountering the end of slice.\n\tErrEOF = stderrors.New(\"ErrEOF: End of file\")\n\n\t// ErrCommitAfterFinish indicates that write batch commit was called after\n\t// finish\n\tErrCommitAfterFinish = stderrors.New(\"Batch commit not permitted after finish\")\n)\n\ntype Flags int\n\nconst (\n\t// Sync indicates that O_DSYNC should be set on the underlying file,\n\t// ensuring that data writes do not return until the data is flushed\n\t// to disk.\n\tSync Flags = 1 << iota\n\t// ReadOnly opens the underlying file on a read-only basis.\n\tReadOnly\n)\n\nvar (\n\t// This is O_DSYNC (datasync) on platforms that support it -- see file_unix.go\n\tdatasyncFileFlag = 0x0\n\n\t// CastagnoliCrcTable is a CRC32 polynomial table","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/y/y.go#L16-L52","documentation":"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.","triggerScenarios":"Thrown at y/y.go:34 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}