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
- 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
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
- 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
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
- Request url protocol must be 'http:' or 'https:': received '
- Request method must be GET
- Response status must not be 206
- Vary header must not contain '*'
- Response body is already used
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/e0bdd5e8be1ac9c2.
Report an issue: GitHub.