{"record":{"id":"c69f90fd0b48d3aa","repo":"clockworklabs/SpacetimeDB","slug":"repo-error-getting-file-metadata-for-segment","errorCode":null,"errorMessage":"repo {}: error getting file metadata for segment {}: {}","messagePattern":"repo (.+?): error getting file metadata for segment (.+?): (.+?)","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/commitlog/src/repo/fs.rs","lineNumber":266,"sourceCode":"                    warn!(\"repo {}: failed to remove {}: {}\", self, lock_path.display(), e);\n                }\n            },\n        );\n\n        // Check whether the segment already exists.\n        // Overwrite it if its length is zero.\n        match fs::metadata(&path) {\n            Ok(stat) => {\n                if stat.len() > 0 {\n                    return Err(io::Error::new(\n                        io::ErrorKind::AlreadyExists,\n                        format!(\"repo {}: segment {} already exists and is non-empty\", self, offset),\n                    ));\n                }\n            }\n            Err(e) => {\n                if e.kind() != io::ErrorKind::NotFound {\n                    return Err(io::Error::new(\n                        e.kind(),\n                        format!(\n                            \"repo {}: error getting file metadata for segment {}: {}\",\n                            self, offset, e\n                        ),\n                    ));\n                }\n            }\n        }\n\n        // The segment file either does not exist, or is of length zero.\n        // Write the header to a temporary file and atomically move it into place.\n        let mut tmp = tempfile::Builder::new().make_in(&self.root.0, |tmp_path| {\n            File::options().read(true).write(true).create_new(true).open(tmp_path)\n        })?;\n        header.write(&mut tmp)?;\n        tmp.as_file_mut().sync_all()?;\n        let segment = tmp.persist(path)?;","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/commitlog/src/repo/fs.rs#L248-L284","documentation":"While checking whether a segment file already exists, fs::metadata on the segment path returned an error other than NotFound (which is the normal, handled 'segment absent' case). The original ErrorKind and message are passed through, so the real cause - PermissionDenied, EIO, path issues - is in the inner error text.","triggerScenarios":"create_segment stats <dir>/<segment> and the stat itself fails: missing execute permission on a path component, an I/O error from the device, or a path that exceeds filesystem limits.","commonSituations":"Running as a non-root user on root-owned directories; flaky NFS/FUSE mounts returning EIO on stat; exotic path configurations.","solutions":["Read the inner {e} and its ErrorKind: fix directory permissions or path components accordingly","If the kind is EIO, check device/dmesg health and remount the filesystem","Reproduce as the same user with `stat <segment path>` to confirm it is environmental"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// smoke-test the path before opening the log\nstd::fs::metadata(&dir).and_then(|m| {\n    if m.is_dir() { Ok(()) } else { Err(io::Error::new(io::ErrorKind::NotFound, \"not a directory\")) }\n})?;","typeGuard":"fn is_segment_metadata_error(e: &io::Error) -> bool {\n    e.to_string().contains(\"error getting file metadata for segment\")\n}","tryCatchPattern":"match result {\n    Ok(v) => v,\n    Err(e) if is_segment_metadata_error(&e) => {\n        // surface the inner kind (PermissionDenied, EIO, ...) for the operator\n        return Err(io::Error::new(e.kind(), format!(\"stat failed on log segment: {e}\")));\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Run the process as a user that owns the log directory","Avoid NFS/FUSE mounts for the log when possible; if used, monitor for EIO","Add a start-up health check that stats every file in the log directory"],"tags":["rust","commitlog","filesystem","metadata","permissions"],"backgroundTag":"filesystem-stat-failed","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}