denoland/deno · error

failed to open in-memory cache db

Error message

failed to open in-memory cache db

What it means

Deno's caches (type-check, node analysis, HTTP cache metadata) can live in an in-memory SQLite database when DENO_CACHE_DB_MODE=memory. This panic fires when rusqlite cannot even create that in-memory connection — practically an allocation failure inside SQLite. The default disk mode is unaffected.

Source

Thrown at ext/cache/sqlite.rs:106

}

impl SqliteBackedCache {
  pub fn new(cache_storage_dir: PathBuf) -> Result<Self, CacheError> {
    let mode = match std::env::var("DENO_CACHE_DB_MODE")
      .unwrap_or_default()
      .as_str()
    {
      "disk" | "" => Mode::Disk,
      "memory" => Mode::InMemory,
      _ => {
        log::warn!("Unknown DENO_CACHE_DB_MODE value, defaulting to disk");
        Mode::Disk
      }
    };

    let connection = if matches!(mode, Mode::InMemory) {
      rusqlite::Connection::open_in_memory()
        .unwrap_or_else(|_| panic!("failed to open in-memory cache db"))
    } else {
      create_cache_storage_dir(&cache_storage_dir)?;

      let path = cache_storage_dir.join("cache_metadata.db");
      let connection = rusqlite::Connection::open(&path).unwrap_or_else(|_| {
        panic!("failed to open cache db at {}", path.display())
      });
      // Enable write-ahead-logging mode.
      let initial_pragmas = "
        -- enable write-ahead-logging mode
        PRAGMA journal_mode=WAL;
        PRAGMA synchronous=NORMAL;
        PRAGMA optimize;
      ";
      connection.execute_batch(initial_pragmas)?;
      connection
    };

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Switch back to disk mode: unset DENO_CACHE_DB_MODE or set it to `disk`
  2. Raise the container/cgroup memory limit or free memory before running
  3. If memory mode previously worked, look for a leak in the workload that consumed the headroom

Example fix

# before
DENO_CACHE_DB_MODE=memory deno run app.ts

# after
DENO_CACHE_DB_MODE=disk deno run app.ts   # or: unset DENO_CACHE_DB_MODE
Defensive patterns

Strategy: fallback

Validate before calling

# only opt into memory mode when it is deliberate; disk is the safe default
unset DENO_CACHE_DB_MODE  # or export DENO_CACHE_DB_MODE=disk

Prevention

When it happens

Trigger: Starting any Deno command with DENO_CACHE_DB_MODE=memory while the process cannot allocate memory for the SQLite handle — severe memory pressure, cgroup/container limits, or ulimit restrictions on the process.

Common situations: CI containers with tight memory caps; developers enabling memory mode to speed up ephemeral CI runs; a leaky parent workload leaving no allocation headroom.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/8414b3d2d9d6c9bf. Report an issue: GitHub.