{"record":{"id":"c9bd29314b20093e","repo":"nautechsystems/nautilus_trader","slug":"market-exit-timer-interval-exceeds-the-nanosecond","errorCode":null,"errorMessage":"Market exit timer interval exceeds the nanosecond range","messagePattern":"Market exit timer interval exceeds the nanosecond range","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/trading/src/strategy/mod.rs","lineNumber":1781,"sourceCode":"                Some(time_in_force),\n                Some(reduce_only),\n                None,\n                None,\n            ) {\n                log::error!(\"Error closing positions for {instrument_id}: {e}\");\n            }\n        }\n\n        let core = StrategyNative::strategy_core_mut(self);\n        let interval_ms = core.config.market_exit_interval_ms;\n        let timer_name = core.market_exit_timer_name;\n\n        log::info!(\"{strategy_id} Setting market exit timer at {interval_ms}ms intervals\");\n\n        let Ok(interval_ns) = DurationNanos::try_from_millis(interval_ms) else {\n            core.is_exiting = false;\n            core.market_exit_attempts = 0;\n            anyhow::bail!(\"Market exit timer interval exceeds the nanosecond range\");\n        };\n        let result = core.clock_mut().set_timer_ns(\n            timer_name.as_str(),\n            interval_ns,\n            None,\n            None,\n            None,\n            None,\n            None,\n        );\n\n        if let Err(e) = result {\n            // Reset exit state on timer failure (caller handles pending_stop)\n            core.is_exiting = false;\n            core.market_exit_attempts = 0;\n            return Err(e);\n        }\n","sourceCodeStart":1763,"sourceCodeEnd":1799,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/trading/src/strategy/mod.rs#L1763-L1799","documentation":"When starting a market exit timer, the strategy converts a millisecond interval to a DurationNanos. If the millisecond value overflows the nanosecond range (too large to fit), the conversion fails, the exiting state and attempt counter are reset, and the strategy aborts the timer setup with this error. It guards the clock timer API against invalid durations.","triggerScenarios":"Calling stop (which drives market_exit) with a market exit timer interval in milliseconds that is too large to represent as nanoseconds (e.g. from a misconfigured config value exceeding u64 nanosecond capacity).","commonSituations":"Config file with an absurd market-exit interval (e.g. seconds entered as nanoseconds, or a typo like 10^18 ms); environment-provided interval parsed without bounds checking.","solutions":["Check the market exit timer interval configuration value and reduce it to a sane millisecond value","Add validation/bounds on the interval before it reaches market_exit (e.g. cap at u64::MAX/1_000_000 ns)","Log and reject the invalid config at startup with a clear message instead of at timer setup"],"exampleFix":"// before\nlet interval_ms = config.market_exit_interval_ms; // 10_000_000_000_000_000\n// after\nanyhow::ensure!(config.market_exit_interval_ms <= MAX_INTERVAL_MS, \"market exit interval too large\");\nlet interval_ms = config.market_exit_interval_ms;","handlingStrategy":"validation","validationCode":"// Rust\nconst MAX_INTERVAL_MS: u64 = u64::MAX / 1_000_000;\nif interval_ms > MAX_INTERVAL_MS {\n    return Err(anyhow::anyhow!(\"interval_ms {interval_ms} exceeds nanosecond range\"));\n}","typeGuard":null,"tryCatchPattern":"// Rust\nmatch strategy.stop() {\n    Err(e) if e.to_string().contains(\"nanosecond range\") => {\n        log::error!(\"fix market exit interval config: {e}\");\n    }\n    other => other?,\n}","preventionTips":["Bound-check duration config values at startup, before the strategy runs","Store intervals in a typed config struct with validated ranges","Never assemble interval values by string concatenation of user input"],"tags":["config","timer","duration-overflow"],"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"}