{"record":{"id":"464ea16bc49c561a","repo":"benbjohnson/litestream","slug":"cannot-remove-tmp-files-w","errorCode":null,"errorMessage":"cannot remove tmp files: %w","messagePattern":"cannot remove tmp files: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":793,"sourceCode":"\t}\n\t// Recreate context for fresh start (handles reopen after close)\n\tdb.ctx, db.cancel = context.WithCancel(context.Background())\n\tdb.mu.Unlock()\n\n\t// Validate fields on database.\n\tif db.Replica == nil {\n\t\treturn fmt.Errorf(\"replica required before opening database\")\n\t}\n\tif db.Replica.Client == nil {\n\t\treturn fmt.Errorf(\"replica client required before opening database\")\n\t}\n\tif db.MinCheckpointPageN <= 0 {\n\t\treturn fmt.Errorf(\"minimum checkpoint page count required\")\n\t}\n\n\t// Clear old temporary files that my have been left from a crash.\n\tif err := removeTmpFiles(db.metaPath); err != nil {\n\t\treturn fmt.Errorf(\"cannot remove tmp files: %w\", err)\n\t}\n\n\t// Set the compactor client once before starting any goroutines.\n\tdb.compactor.VerifyCompaction = db.VerifyCompaction\n\tdb.compactor.RetentionEnabled = db.RetentionEnabled\n\tdb.compactor.client = db.Replica.Client\n\n\t// Start monitoring SQLite database in a separate goroutine.\n\tif db.MonitorInterval > 0 {\n\t\tdb.wg.Add(1)\n\t\tgo func() { defer db.wg.Done(); db.monitor() }()\n\t}\n\n\t// Mark as opened only after successful initialization.\n\tdb.mu.Lock()\n\tdb.opened = true\n\tdb.mu.Unlock()\n","sourceCodeStart":775,"sourceCodeEnd":811,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/db.go#L775-L811","documentation":"DB.Open calls removeTmpFiles(db.metaPath) to clean temporary files left over from a previous crash, and wraps any failure from that helper with this error. Tmp files are transient artifacts during replication/checkpointing; failure to remove them usually indicates a filesystem-level problem in the database's metadata directory.","triggerScenarios":"removeTmpFiles returns an error while scanning/removing files under the directory of db.metaPath — e.g. an OS-level read error or unexpected failure enumerating the directory.","commonSituations":"Read-only or full filesystem containing the database and its .litestream metadata; permission changes after restoring a volume; NFS/EFS hiccups during directory enumeration.","solutions":["Check filesystem permissions and free space on the volume holding the database and its metadata directory.","Run as the user that owns the database files (or fix ownership with chown).","Inspect the wrapped inner error (%w) to identify whether it is a directory-read or file-remove failure, and address that path."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// check filesystem is writable before opening\nif err := os.WriteFile(filepath.Join(filepath.Dir(dbPath), \".probe\"), nil, 0o600); err != nil {\n    return fmt.Errorf(\"data dir not writable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := db.Open(); err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) {\n        log.Printf(\"filesystem problem at %s: %v\", perr.Path, perr.Err)\n    }\n    return err\n}","preventionTips":["Monitor disk space and permissions on the database volume.","Run litestream as the same user owning the DB files.","Avoid read-only mounts for the database directory."],"tags":["filesystem","cleanup","io"],"backgroundTag":"file-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"}