{"record":{"id":"b66de9fb47fb2405","repo":"nautechsystems/nautilus_trader","slug":"time-went-backwards-b66de9","errorCode":null,"errorMessage":"Time went backwards","messagePattern":"Time went backwards","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/cache/mod.rs","lineNumber":3027,"sourceCode":"    }\n\n    /// Checks integrity of data within the cache.\n    ///\n    /// All data should be loaded from the database prior to this call.\n    /// If an error is found then a log error message will also be produced.\n    ///\n    /// # Panics\n    ///\n    /// Panics if failure calling system clock.\n    #[must_use]\n    pub fn check_integrity(&mut self) -> bool {\n        let mut error_count = 0;\n        let failure = \"Integrity failure\";\n\n        // Get current timestamp in microseconds\n        let timestamp_us = SystemTime::now()\n            .duration_since(UNIX_EPOCH)\n            .expect(\"Time went backwards\")\n            .as_micros();\n\n        log::info!(\"Checking data integrity\");\n\n        // Check object caches\n        for account_id in self.accounts.keys() {\n            if !self\n                .index\n                .venue_account\n                .contains_key(&account_id.get_issuer())\n            {\n                log::error!(\n                    \"{failure} in accounts: {account_id} not found in `self.index.venue_account`\",\n                );\n                error_count += 1;\n            }\n        }\n","sourceCodeStart":3009,"sourceCodeEnd":3045,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/cache/mod.rs#L3009-L3045","documentation":"The integrity check captures the start timestamp with SystemTime::now().duration_since(UNIX_EPOCH) and expects it to succeed. If the OS reports a time before the Unix epoch, duration_since returns Err and this expect panics. It guards against a fundamentally broken system clock.","triggerScenarios":"Calling an integrity-check method (check_* on Cache) while the host clock is set earlier than 1970-01-01T00:00:00Z, e.g. during system boot with an unset RTC or a clock reset.","commonSituations":"Embedded systems or VMs without RTC battery starting with epoch 0 or an earlier default; container images with wrong clock; deliberate clock manipulation in tests; NTP failures leaving a bad system time.","solutions":["Fix the host system clock (sync via NTP, set correct date) and rerun","If clock correctness cannot be guaranteed, replace SystemTime with a monotonic or library-injected clock","Check `date`/`timedatectl` output before running the integrity check in scripts","Guard the call site: if time is before UNIX_EPOCH, skip or delay the integrity check"],"exampleFix":"// before\nlet timestamp_us = SystemTime::now()\n    .duration_since(UNIX_EPOCH)\n    .expect(\"Time went backwards\")\n    .as_micros();\n// after\nlet timestamp_us = SystemTime::now()\n    .duration_since(UNIX_EPOCH)\n    .map_err(|_| anyhow!(\"system clock is before UNIX_EPOCH; sync the clock\"))?\n    .as_micros();","handlingStrategy":"validation","validationCode":"if SystemTime::now().duration_since(UNIX_EPOCH).is_err() {\n    eprintln!(\"System clock is before UNIX_EPOCH; fix clock before integrity check\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"// Panics are not catchable; pre-validate the clock\nmatch SystemTime::now().duration_since(UNIX_EPOCH) {\n    Ok(t) => println!(\"clock ok: {}us\", t.as_micros()),\n    Err(e) => eprintln!(\"clock invalid: {e}\"),\n}","preventionTips":["Sync the host clock via NTP and monitor time sync health","Check `timedatectl`/clock sanity before long-running trading processes","Avoid running integrity checks on freshly booted RTC-less machines before time sync"],"tags":["rust","panic","clock","system-time"],"backgroundTag":"invalid-argument-value","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}