{"record":{"id":"87e63e23d6ace7ce","repo":"nautechsystems/nautilus_trader","slug":"heartbeat-interval-secs-must-be-greater-than-0","errorCode":null,"errorMessage":"heartbeat_interval_secs must be greater than 0","messagePattern":"heartbeat_interval_secs must be greater than 0","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/redis/msgbus.rs","lineNumber":285,"sourceCode":"    }\n}\n\nimpl RedisMessageBusBacking {\n    /// Creates a new [`RedisMessageBusBacking`] instance for the given `trader_id`, `instance_id`, and `config`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the heartbeat interval is configured as zero seconds.\n    pub fn new(\n        trader_id: TraderId,\n        instance_id: UUID4,\n        config: MessageBusConfig,\n        backing: RedisMessageBusConfig,\n    ) -> anyhow::Result<Self> {\n        install_cryptographic_provider();\n\n        if config.heartbeat_interval_secs == Some(0) {\n            anyhow::bail!(\"heartbeat_interval_secs must be greater than 0\");\n        }\n\n        let external_streams = config.external_streams.clone().unwrap_or_default();\n        let heartbeat_interval_secs = config.heartbeat_interval_secs;\n        let publish = backing.clone();\n\n        let (pub_tx, pub_rx) = tokio::sync::mpsc::unbounded_channel::<BusMessage>();\n\n        // Create publish task (start the runtime here for now)\n        let pub_handle = Some(get_runtime().spawn(async move {\n            if let Err(e) = publish_messages(pub_rx, trader_id, instance_id, config, publish).await\n            {\n                log_task_error(MSGBUS_PUBLISH, &e);\n            }\n        }));\n\n        // Conditionally create stream task and channel if external streams configured\n        let stream_signal = Arc::new(AtomicBool::new(false));","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/redis/msgbus.rs#L267-L303","documentation":"RedisMessageBus::new validates MessageBusConfig before constructing the bus. A heartbeat interval of Some(0) is rejected because a zero-second heartbeat period would spin the heartbeat task in a tight loop, so the constructor fails fast with this error instead.","triggerScenarios":"Constructing the message bus with MessageBusConfig { heartbeat_interval_secs: Some(0), .. } — passing zero explicitly rather than None (disabled) or a positive number.","commonSituations":"Copy-pasting a config template and setting 0 to 'disable' the heartbeat; computing the interval from an expression that evaluates to 0 (e.g. seconds parsed from an empty/zero env var).","solutions":["Set heartbeat_interval_secs to None if you want the heartbeat disabled","Set a positive value, e.g. Some(30) for a 30-second heartbeat","Clamp or validate the value where the config is loaded (env var / config file parsing) before constructing the bus","Check the expression producing the interval — a zero-derived value usually signals an unset input"],"exampleFix":"// before\nlet config = MessageBusConfig { heartbeat_interval_secs: Some(0), .. };\n// after\nlet config = MessageBusConfig { heartbeat_interval_secs: None, .. }; // or Some(30)","handlingStrategy":"validation","validationCode":"assert!(config.heartbeat_interval_secs.map_or(true, |s| s > 0), \"heartbeat_interval_secs must be > 0 or None\");","typeGuard":null,"tryCatchPattern":"let bus = RedisMessageBus::new(config, backing)\n    .map_err(|e| if e.to_string().contains(\"heartbeat_interval_secs\") { ConfigError::BadHeartbeat } else { e })?;","preventionTips":["Use None (not Some(0)) to disable the heartbeat","Validate config at load time, before constructing the bus","Derive intervals with saturating/max bounds, e.g. secs.max(1)"],"tags":["config","validation","redis"],"backgroundTag":"invalid-config-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"}