{"record":{"id":"e0bdd5e8be1ac9c2","repo":"denoland/deno","slug":"systemtime-is-before-unix-epoch","errorCode":null,"errorMessage":"SystemTime is before unix epoch","messagePattern":"SystemTime is before unix epoch","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"ext/cache/sqlite.rs","lineNumber":278,"sourceCode":"      let mut names = Vec::new();\n      for row in rows {\n        names.push(row?);\n      }\n      Ok::<Vec<String>, CacheError>(names)\n    })\n    .await?\n  }\n\n  pub async fn put(\n    &self,\n    request_response: CachePutRequest,\n    resource: Option<Rc<dyn Resource>>,\n  ) -> Result<(), CacheError> {\n    let db = self.connection.clone();\n    let cache_storage_dir = self.cache_storage_dir.clone();\n    let now = SystemTime::now()\n      .duration_since(UNIX_EPOCH)\n      .expect(\"SystemTime is before unix epoch\");\n\n    if let Some(resource) = resource {\n      let body_key = hash(&format!(\n        \"{}_{}\",\n        &request_response.request_url,\n        now.as_nanos()\n      ));\n      let responses_dir =\n        get_responses_dir(cache_storage_dir, request_response.cache_id);\n      let response_path = responses_dir.join(&body_key);\n      let mut file = tokio::fs::File::create(response_path).await?;\n      let mut buf = BufMutView::new(64 * 1024);\n      loop {\n        let (size, buf2) = resource\n          .clone()\n          .read_byob(buf)\n          .await\n          .map_err(CacheError::Other)?;","sourceCodeStart":260,"sourceCodeEnd":296,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/cache/sqlite.rs#L260-L296","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Correct the system clock and enable NTP synchronization","Fix the host clock for VMs and containers, which usually inherit host time","Replace the CMOS battery on hardware that resets to epoch on boot","Until the clock is fixed, disable Cache API writes (cache.put) in the application"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if (Date.now() < 0) {\n  throw new Error(\"system clock is before 1970; fix time/NTP before using the Cache API\");\n}\nawait cache.put(request, response);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run NTP/time synchronization on hosts and containers that use the Cache API","Check Date.now() sanity at app startup and refuse to serve with a bad clock","Keep VM/host clocks accurate after snapshot restores"],"tags":["cache-api","cache-storage","system-clock","panic","sqlite"],"backgroundTag":"system-clock-before-epoch","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}