{"record":{"id":"2427e11712676161","repo":"benbjohnson/litestream","slug":"reset-failed-w","errorCode":null,"errorMessage":"reset failed: %w","messagePattern":"reset failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/reset.go","lineNumber":119,"sourceCode":"\t\tif len(files) == 0 {\n\t\t\tfmt.Println(\"No local LTX files would be removed.\")\n\t\t\treturn nil\n\t\t}\n\n\t\tfmt.Println(\"Files that would be removed:\")\n\t\tfor _, file := range files {\n\t\t\tfmt.Printf(\"  %s\\n\", file)\n\t\t}\n\t\tfmt.Println(\"No files were removed.\")\n\t\treturn nil\n\t}\n\n\t// Perform the reset\n\tfmt.Printf(\"Resetting local Litestream state for: %s\\n\", dbPath)\n\tfmt.Printf(\"Removing: %s\\n\", db.LTXDir())\n\n\tif err := db.ResetLocalState(ctx); err != nil {\n\t\treturn fmt.Errorf(\"reset failed: %w\", err)\n\t}\n\n\tfmt.Println(\"Reset complete. Next replication sync will create a fresh snapshot.\")\n\treturn nil\n}\n\nfunc localLTXFiles(root string) ([]string, error) {\n\tif _, err := os.Stat(root); os.IsNotExist(err) {\n\t\treturn nil, nil\n\t} else if err != nil {\n\t\treturn nil, err\n\t}\n\n\tvar files []string\n\tif err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/reset.go#L101-L137","documentation":"`litestream reset` deletes the database's local LTX state via db.ResetLocalState(ctx). If that removal fails (files locked, permission denied, partial deletion errors), the error is wrapped as \"reset failed\". Because reset is destructive, a failure here may leave the LTX directory partially removed — the next replication sync will still create a fresh snapshot once the issue is resolved.","triggerScenarios":"`litestream reset <dbpath>` where ResetLocalState cannot delete the LTX directory: open file handles/locks on LTX files (another litestream or reader process), permission denied on files or parent dir, read-only filesystem, or context cancellation mid-delete.","commonSituations":"Two litestream processes running against the same db; resetting while backups/litestream replicate is active; running in containers with read-only volume mounts; SELinux/AppArmor denying deletion.","solutions":["Stop any other litestream processes or readers holding the LTX dir open, then retry","Check the wrapped inner error for permission vs I/O specifics and fix ownership: `chown -R` or run as the db's owning user","Verify the filesystem is writable (not mounted ro): `mount | grep <path>`","Retry the reset; deletion is idempotent, so a partial previous attempt just finishes"],"exampleFix":"// before (litestream still running)\nlitestream reset /var/lib/db/app.db\n// after\nsystemctl stop litestream\nlitestream reset /var/lib/db/app.db\nsystemctl start litestream","handlingStrategy":"try-catch","validationCode":"// Ensure no other litestream holds the state\nif err := exec.Command(\"pgrep\", \"-f\", \"litestream run\").Run(); err == nil {\n    return fmt.Errorf(\"litestream is running; stop it before reset\")\n}","typeGuard":null,"tryCatchPattern":"err := runReset(ctx, dbPath)\nvar perr *fs.PathError\nif errors.As(err, &perr) && errors.Is(perr.Err, syscall.EACCES) {\n    // retry with elevated permissions or fixed ownership\n}\nif errors.Is(err, context.Canceled) { /* user aborted mid-delete; re-run */ }","preventionTips":["Stop the litestream service before resetting its state","Ensure writable, local filesystems for .litestream directories","Treat reset as idempotent and retry on transient failures"],"tags":["cli","filesystem","destructive-operation"],"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-14T05:17:10.506Z"}