databendlabs/databend · error

internal error: entered unreachable code

Error message

internal error: entered unreachable code

What it means

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).

Solutions

  1. Clean the disk cache directory (remove unexpected subdirectories/symlinks or wipe the cache) and restart so keys are regenerated
  2. Check the data/cache storage configuration (cache path) for misconfiguration and point it to an empty, dedicated directory
  3. Report as a bug: recovery should skip invalid paths instead of unreachable!()

Example fix

// before
None => {
    // only called during init, and only path of files are passed in
    unreachable!()
}
// after
None => {
    tracing::warn!("skip non-file cache path {:?}", relative_path);
    String::new()
}
Defensive patterns

Strategy: validation

Validate before calling

// check cache dir contains only regular files before restart
find <cache_dir> -mindepth 1 \! -type f -print
# output must be empty; else clean the cache dir

Try / catch

// on startup error 1001 mentioning disk_cache, wipe cache dir and restart
// databend-cache is safe to delete: entries are rebuilt from storage

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of databendlabs/databend@288d84d76e (2026-09-11). Data as JSON: /api/errors/6fa4a6450a4b7124. Report an issue: GitHub.

Appendix: source

Thrown at src/query/storages/common/cache/src/providers/disk_cache/disk_cache.rs:355

            Some(_) => {
                let path = self.abs_path_of_cache_key(&cache_key);
                fs::remove_file(&path).map_err(|e| {
                    error!("Error removing file from cache: `{:?}`: {}", path, e);
                    Into::into(e)
                })
            }
            None => Ok(()),
        }
    }
}

fn recovery_cache_key_from_path(relative_path: &Path) -> String {
    let key_string = match relative_path.file_name() {
        Some(file_name) => match file_name.to_str() {
            Some(str) => str.to_owned(),
            None => {
                // relative_path is constructed by ourself, and shall be valid utf8 string
                unreachable!()
            }
        },
        None => {
            // only called during init, and only path of files are passed in
            unreachable!()
        }
    };
    key_string
}

pub mod io_result {
    use std::error::Error as StdError;
    use std::fmt;
    use std::io;
    use std::path::PathBuf;

    /// Errors returned by this crate.
    #[derive(Debug)]

View on GitHub (pinned to 288d84d76e)