{"record":{"id":"06abc81bd01743b1","repo":"nautechsystems/nautilus_trader","slug":"system-time-overflow-value-exceeds-u64-max-nanos","errorCode":null,"errorMessage":"System time overflow: value exceeds u64::MAX nanoseconds","messagePattern":"System time overflow: value exceeds u64::MAX nanoseconds","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/core/src/time.rs","lineNumber":136,"sourceCode":"        // running under simulation are always inside a runtime, so they\n        // continue to receive virtual time.\n        match madsim::time::TimeHandle::try_current() {\n            Some(handle) => handle.now_time(),\n            None => SystemTime::now(),\n        }\n    }\n}\n\n/// Returns the current UNIX time in nanoseconds, based on [`SystemTime::now()`].\n///\n/// # Panics\n///\n/// Panics if the duration in nanoseconds exceeds `u64::MAX`.\n#[inline(always)]\n#[must_use]\npub fn nanos_since_unix_epoch() -> u64 {\n    u64::try_from(duration_since_unix_epoch().as_nanos())\n        .expect(\"System time overflow: value exceeds u64::MAX nanoseconds\")\n}\n\n/// Represents an atomic timekeeping structure.\n///\n/// [`AtomicTime`] can act as a real-time clock or static clock based on its mode.\n/// It uses an [`AtomicU64`] to atomically update the value using only immutable\n/// references.\n///\n/// The `realtime` flag indicates which mode the clock is currently in.\n/// For concurrency, this struct uses atomic operations with appropriate memory orderings:\n/// - **Acquire/Release** for reading/writing in **static mode**.\n/// - **Compare-and-exchange (`AcqRel`)** in real-time mode to guarantee monotonic increments.\n///\n/// The mode flag and timestamp are private so every update flows through the methods\n/// that uphold the monotonicity and mode invariants.\n#[repr(C)]\n#[derive(Debug)]\npub struct AtomicTime {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/core/src/time.rs#L118-L154","documentation":"nanos_since_unix_epoch in crates/core/src/time.rs:136 converts the duration since the Unix epoch to u64 nanoseconds, panicking via expect(\"System time overflow: value exceeds u64::MAX nanoseconds\") when the value exceeds u64::MAX. Since u64 nanoseconds cover roughly the year 2554, this fires only when the system clock is set absurdly far in the future (or a mocked clock misbehaves), which the documented invariant treats as an unrecoverable environment error.","triggerScenarios":"Calling nanos_since_unix_epoch (via run_impl, abort_run, end, is_within_last_24_hours, etc.) when the OS clock is set past ~year 2554: manual date misconfiguration, NTP serving a wildly wrong time, or a test/virtual clock configured with an out-of-range epoch offset.","commonSituations":"Typo'd manual date setting (e.g. year 30000); misconfigured mock clock fixtures advancing virtual time by huge multiples; broken NTP servers; deterministic simulation clocks seeded with milliseconds instead of seconds (or vice versa) producing runaway values.","solutions":["Correct the system clock (NTP sync) and verify with `date` before restarting the process.","Check any simulation/virtual clock seeding code: confirm the epoch offset unit (seconds vs millis vs nanos) and magnitude.","If a fake clock is used in tests, clamp its advancement so accumulated time stays within u64 nanoseconds.","Audit NTP sources and time-jump handling; log the clock value at startup to catch absurd settings early."],"exampleFix":"# before (virtual clock seeded in nanos instead of seconds)\nstart = 1_700_000_000_000_000_000 * 1_000  # runaway offset\n# after\nstart = 1_700_000_000  # seconds since epoch, correct unit","handlingStrategy":"validation","validationCode":"use std::time::{SystemTime, UNIX_EPOCH};\nlet d = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();\nassert!(u64::try_from(d.as_nanos()).is_ok(), \"clock value exceeds u64 nanos; check clock config\");","typeGuard":"fn nanos_fit_u64(d: std::time::Duration) -> bool {\n    u64::try_from(d.as_nanos()).is_ok()\n}","tryCatchPattern":null,"preventionTips":["Verify the OS clock (`date`) is sane before starting long-running processes.","Double-check units when seeding simulation/virtual clocks (seconds vs millis vs nanos).","Clamp mock-clock advancement in tests so accumulated time cannot overflow u64 nanos.","Audit NTP sources; log the epoch offset at startup to catch absurd values early."],"tags":["time","overflow","system-clock","panic"],"backgroundTag":"value-out-of-range","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"}