{"record":{"id":"861dd70a18f24e70","repo":"clockworklabs/SpacetimeDB","slug":"failed-to-open-file-for-fsync","errorCode":null,"errorMessage":"failed to open file {} for fsync: {}","messagePattern":"failed to open file (.+?) for fsync: (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/snapshot/src/lib.rs","lineNumber":1599,"sourceCode":"                    io::Error::new(\n                        e.kind(),\n                        format!(\"failed to open directory {} for fsync: {}\", path.display(), e),\n                    )\n                })?\n                .sync_all()\n                .map_err(|e| io::Error::new(e.kind(), format!(\"failed to fsync directory {}: {}\", path.display(), e))),\n            Self::File(path) => {\n                File::options()\n                    .read(true)\n                    // Windows needs the file to be writable for `sync_all` to work.\n                    // Set all the open options explicitly, just for visibility.\n                    .write(true)\n                    .truncate(false)\n                    .create(false)\n                    .append(false)\n                    .open(path)\n                    .map_err(|e| {\n                        io::Error::new(\n                            e.kind(),\n                            format!(\"failed to open file {} for fsync: {}\", path.display(), e),\n                        )\n                    })?\n                    .sync_all()\n                    .map_err(|e| io::Error::new(e.kind(), format!(\"failed to fsync file {}: {}\", path.display(), e)))\n            }\n        }\n    }\n}\n\n#[cfg(test)]\nmod tests {\n    use std::fs::OpenOptions;\n\n    use tempfile::tempdir;\n\n    use super::*;","sourceCodeStart":1581,"sourceCodeEnd":1617,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/snapshot/src/lib.rs#L1581-L1617","documentation":"The file variant of the snapshot durability sync: opening the just-written snapshot file with read+write options (write access is required for sync_all to work on Windows) failed. The file vanished between being written and being synced, or permissions/read-only mounts block opening it for write.","triggerScenarios":"The snapshot file deleted or moved by another process between write and sync; a read-only filesystem or container bind mount; permission mismatch on the file or directory.","commonSituations":"Antivirus or backup agents locking/removing fresh files; concurrent snapshot cleanup; read-only bind mounts in containers.","solutions":["Exclude snapshot directories from antivirus/backup interference.","Ensure the snapshot volume is writable and not mounted read-only.","Eliminate processes that concurrently delete snapshot files."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"use std::fs;\n\nfn snapshot_file_syncable(path: &str) -> bool {\n    fs::OpenOptions::new().read(true).write(true).open(path).is_ok()\n}","typeGuard":null,"tryCatchPattern":"match sync_result {\n    Err(e) if e.to_string().contains(\"failed to open file\") => {\n        // File vanished between write and sync (AV/backup/cleanup) or the mount is\n        // read-only: remove interference, then re-run the snapshot.\n    }\n    r => r,\n}","preventionTips":["Exclude snapshot directories from antivirus and backup agents that lock or move fresh files.","Ensure snapshot volumes are mounted read-write.","Avoid concurrent processes deleting snapshot files."],"tags":["snapshot","fsync","file-open","rust"],"backgroundTag":"file-open-failure","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}