denoland/deno · critical

SystemTime is before unix epoch

Error message

SystemTime is before unix epoch

What it means

The Cache Storage implementation (the fetch-spec caches / Cache.put API, SQLite-backed) timestamps each write with SystemTime::now() since the Unix epoch, and duration_since(UNIX_EPOCH) is expected to succeed. When writing a cached response body, a system clock set before 1970-01-01 makes the subtraction fail and .expect() panics, crashing the process inside the op.

Source

Thrown at ext/cache/sqlite.rs:278

      let mut names = Vec::new();
      for row in rows {
        names.push(row?);
      }
      Ok::<Vec<String>, CacheError>(names)
    })
    .await?
  }

  pub async fn put(
    &self,
    request_response: CachePutRequest,
    resource: Option<Rc<dyn Resource>>,
  ) -> Result<(), CacheError> {
    let db = self.connection.clone();
    let cache_storage_dir = self.cache_storage_dir.clone();
    let now = SystemTime::now()
      .duration_since(UNIX_EPOCH)
      .expect("SystemTime is before unix epoch");

    if let Some(resource) = resource {
      let body_key = hash(&format!(
        "{}_{}",
        &request_response.request_url,
        now.as_nanos()
      ));
      let responses_dir =
        get_responses_dir(cache_storage_dir, request_response.cache_id);
      let response_path = responses_dir.join(&body_key);
      let mut file = tokio::fs::File::create(response_path).await?;
      let mut buf = BufMutView::new(64 * 1024);
      loop {
        let (size, buf2) = resource
          .clone()
          .read_byob(buf)
          .await
          .map_err(CacheError::Other)?;

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Correct the system clock and enable NTP synchronization
  2. Fix the host clock for VMs and containers, which usually inherit host time
  3. Replace the CMOS battery on hardware that resets to epoch on boot
  4. Until the clock is fixed, disable Cache API writes (cache.put) in the application
Defensive patterns

Strategy: validation

Validate before calling

if (Date.now() < 0) {
  throw new Error("system clock is before 1970; fix time/NTP before using the Cache API");
}
await cache.put(request, response);

Prevention

When it happens

Trigger: await caches.open(name) followed by cache.put(request, response) on a machine whose system clock reads before the Unix epoch: dead CMOS battery, restored VM snapshot, an offline device that never NTP-synced, or a container with corrupted time.

Common situations: Embedded devices and VMs with dead RTC batteries booting to 1970; snapshot-restored VMs; sandboxed test environments; hardware whose clock resets on every power loss.

Related errors


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