{"record":{"id":"6fa4a6450a4b7124","repo":"databendlabs/databend","slug":"internal-error-entered-unreachable-code-6fa4a6","errorCode":null,"errorMessage":"internal error: entered unreachable code","messagePattern":"internal error: entered unreachable code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/query/storages/common/cache/src/providers/disk_cache/disk_cache.rs","lineNumber":355,"sourceCode":"            Some(_) => {\n                let path = self.abs_path_of_cache_key(&cache_key);\n                fs::remove_file(&path).map_err(|e| {\n                    error!(\"Error removing file from cache: `{:?}`: {}\", path, e);\n                    Into::into(e)\n                })\n            }\n            None => Ok(()),\n        }\n    }\n}\n\nfn recovery_cache_key_from_path(relative_path: &Path) -> String {\n    let key_string = match relative_path.file_name() {\n        Some(file_name) => match file_name.to_str() {\n            Some(str) => str.to_owned(),\n            None => {\n                // relative_path is constructed by ourself, and shall be valid utf8 string\n                unreachable!()\n            }\n        },\n        None => {\n            // only called during init, and only path of files are passed in\n            unreachable!()\n        }\n    };\n    key_string\n}\n\npub mod io_result {\n    use std::error::Error as StdError;\n    use std::fmt;\n    use std::io;\n    use std::path::PathBuf;\n\n    /// Errors returned by this crate.\n    #[derive(Debug)]","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/databendlabs/databend/blob/288d84d76e20a2f8f7173bda9691eb6ece301aa9/src/query/storages/common/cache/src/providers/disk_cache/disk_cache.rs#L337-L373","documentation":"When rebuilding cache keys from file names during fuzzy-restart recovery of the disk cache, the code expects every path it constructed itself to end in a valid UTF-8 file name. If `relative_path.file_name()` returns None, the assumption is violated and the code hits `unreachable!()` (internal error 1001).","triggerScenarios":"Running disk-cache recovery (fuzzy_restart) when an entry in the cache directory is not a regular file path — e.g. `.`/`..`, a directory, or a path with no final component being fed into recovery_cache_key_from_path.","commonSituations":"Corrupted or manually modified disk cache directory (symlinks, nested dirs, empty entries) on the configured cache location; unusual mounts or leftover files after a crash.","solutions":["Clean the disk cache directory (remove unexpected subdirectories/symlinks or wipe the cache) and restart so keys are regenerated","Check the data/cache storage configuration (cache path) for misconfiguration and point it to an empty, dedicated directory","Report as a bug: recovery should skip invalid paths instead of unreachable!()"],"exampleFix":"// before\nNone => {\n    // only called during init, and only path of files are passed in\n    unreachable!()\n}\n// after\nNone => {\n    tracing::warn!(\"skip non-file cache path {:?}\", relative_path);\n    String::new()\n}","handlingStrategy":"validation","validationCode":"// check cache dir contains only regular files before restart\nfind <cache_dir> -mindepth 1 \\! -type f -print\n# output must be empty; else clean the cache dir","typeGuard":null,"tryCatchPattern":"// on startup error 1001 mentioning disk_cache, wipe cache dir and restart\n// databend-cache is safe to delete: entries are rebuilt from storage","preventionTips":["Keep the disk-cache directory exclusive to Databend (no shared/foreign tools)","Point the cache to a dedicated local path in config","After crashes or restores, clean the cache directory before restart"],"tags":["rust","disk-cache","internal-error","recovery"],"backgroundTag":"internal-invariant-violation","analyzedSha":"288d84d76e20a2f8f7173bda9691eb6ece301aa9","analyzedAt":"2026-09-11T11:29:36.208Z","contentChangedAt":"2026-09-11T11:29:36.208Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}