{"record":{"id":"523fc879589bf53e","repo":"benbjohnson/litestream","slug":"commit-transaction-w","errorCode":null,"errorMessage":"commit transaction: %w","messagePattern":"commit transaction: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream-test/populate.go","lineNumber":210,"sourceCode":"\t\t}\n\n\t\tfor j := i; j < batchEnd; j++ {\n\t\t\tcryptorand.Read(data)\n\t\t\ttextField := fmt.Sprintf(\"row_%d_%d\", i, j)\n\t\t\tintField := rand.Int63()\n\t\t\tfloatField := rand.Float64() * 1000\n\t\t\ttimestamp := time.Now().Unix()\n\n\t\t\tif _, err := stmt.Exec(data, textField, intField, floatField, timestamp); err != nil {\n\t\t\t\tstmt.Close()\n\t\t\t\ttx.Rollback()\n\t\t\t\treturn fmt.Errorf(\"insert row: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tstmt.Close()\n\t\tif err := tx.Commit(); err != nil {\n\t\t\treturn fmt.Errorf(\"commit transaction: %w\", err)\n\t\t}\n\n\t\tselect {\n\t\tcase <-ctx.Done():\n\t\t\treturn ctx.Err()\n\t\tdefault:\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (c *PopulateCommand) Usage() {\n\tfmt.Fprintln(c.Main.Stdout, `\nPopulate a SQLite database to a target size for testing.\n\nUsage:\n","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream-test/populate.go#L192-L228","documentation":"populateTable wraps a failed tx.Commit in this error. After inserting all rows of a batch the transaction is committed to make the batch durable; the WAL then grows and litestream can pick up the change. A commit failure means the entire batch is rolled back and population aborts (ctx cancellation is checked after each successful commit, not here).","triggerScenarios":"tx.Commit() fails: disk full while flushing WAL frames, I/O error on the WAL or database file, the database was locked/invalidated by another connection during the transaction, or driver connection loss.","commonSituations":"Large BatchSize making big transactions that exhaust free space when written to the WAL; filesystem errors (quota, read-only remount); a concurrent process forcing WAL checkpoint failures.","solutions":["Check free disk space including room for WAL growth; reduce BatchSize if transactions are too large.","Inspect the wrapped SQLite error for SQLITE_FULL/SQLITE_IOERR.","Verify the filesystem is writable and quotas are not exceeded.","Ensure only one writer (this tool) touches the database during population."],"exampleFix":"// before\nif err := tx.Commit(); err != nil {\n    return fmt.Errorf(\"commit transaction: %w\", err)\n}\n// after\nif err := tx.Commit(); err != nil {\n    return fmt.Errorf(\"commit transaction (batch %d-%d): %w\", i, batchEnd, err) // include batch range for diagnosis\n}","handlingStrategy":"validation","validationCode":"// ensure free space for WAL before large batch commits\nvar st syscall.Statfs_t\nif err := syscall.Statfs(filepath.Dir(c.DB), &st); err == nil {\n    avail := int64(st.Bavail) * int64(st.Bsize)\n    if avail < int64(c.BatchSize*c.RowSize)*4 {\n        return fmt.Errorf(\"low disk for WAL: %d bytes available\", avail)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := tx.Commit(); err != nil {\n    if strings.Contains(err.Error(), \"SQLITE_FULL\") || strings.Contains(err.Error(), \"SQLITE_IOERR\") {\n        // operational failure: free space / check fs, then retry run\n        return fmt.Errorf(\"commit transaction (operational): %w\", err)\n    }\n    return fmt.Errorf(\"commit transaction: %w\", err)\n}","preventionTips":["Size BatchSize so each transaction's WAL write fits free disk comfortably.","Monitor disk usage during long populations.","Use a local, quota-free filesystem for the test database.","Check ctx.Done() before starting a new batch instead of relying on commit errors to abort."],"tags":["sqlite","transaction","commit"],"backgroundTag":"database-write-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}