{"record":{"id":"9d53b47e55aaf8eb","repo":"benbjohnson/litestream","slug":"truncate-buffer-w","errorCode":null,"errorMessage":"truncate buffer: %w","messagePattern":"truncate buffer: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"vfs.go","lineNumber":2237,"sourceCode":"\t\tf.bufferNextOff += int64(len(data))\n\t}\n\n\t// Write page data (no header, just raw page data)\n\tif _, err := f.bufferFile.WriteAt(data, writeOffset); err != nil {\n\t\treturn fmt.Errorf(\"write page to buffer: %w\", err)\n\t}\n\n\t// Update dirty map with offset\n\tf.dirty[pgno] = writeOffset\n\n\treturn nil\n}\n\n// clearWriteBuffer clears and resets the write buffer after successful sync.\nfunc (f *VFSFile) clearWriteBuffer() error {\n\t// Truncate file to zero\n\tif err := f.bufferFile.Truncate(0); err != nil {\n\t\treturn fmt.Errorf(\"truncate buffer: %w\", err)\n\t}\n\n\t// Reset next write offset\n\tf.bufferNextOff = 0\n\n\treturn nil\n}\n\nfunc (f *VFSFile) FileSize() (size int64, err error) {\n\tpageSize, err := f.pageSizeBytes()\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\n\tf.mu.Lock()\n\tfor pgno := range f.index {\n\t\tif v := int64(pgno) * int64(pageSize); v > size {\n\t\t\tsize = v","sourceCodeStart":2219,"sourceCodeEnd":2255,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/vfs.go#L2219-L2255","documentation":"Wraps bufferFile.Truncate(0) failure in VFSFile.clearWriteBuffer, which resets the write-buffer file after a successful sync. Fires when the temporary buffer backing file cannot be truncated, leaving stale page data that would corrupt subsequent buffered writes.","triggerScenarios":"Thrown at vfs.go:2237 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the health and permissions of the buffer file","Restart the process to re-create the buffer if the file was deleted"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}