{"record":{"id":"5b488edad7251c63","repo":"nautechsystems/nautilus_trader","slug":"cannot-set-cache-database-while-node-is-running-s","errorCode":null,"errorMessage":"Cannot set cache database while node is running, set it before running the node","messagePattern":"Cannot set cache database while node is running, set it before running the node","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/live/src/node/mod.rs","lineNumber":2605,"sourceCode":"    pub fn is_running(&self) -> bool {\n        self.state().is_running()\n    }\n\n    /// Sets the cache database adapter for persistence.\n    ///\n    /// This allows setting a database adapter (e.g., PostgreSQL, Redis) after the node\n    /// is built but before it starts running. The database adapter is used to persist\n    /// cache data for recovery and state management.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the node is already running.\n    pub fn set_cache_database(\n        &mut self,\n        database: Box<dyn CacheDatabaseAdapter>,\n    ) -> anyhow::Result<()> {\n        if self.state() != NodeState::Idle {\n            anyhow::bail!(\n                \"Cannot set cache database while node is running, set it before running the node\"\n            );\n        }\n\n        self.kernel.cache().borrow_mut().set_database(database);\n        Ok(())\n    }\n\n    /// Returns the execution manager.\n    #[must_use]\n    pub fn exec_manager(&self) -> &ExecutionManager {\n        &self.exec_manager\n    }\n\n    /// Returns a mutable reference to the execution manager.\n    #[must_use]\n    pub fn exec_manager_mut(&mut self) -> &mut ExecutionManager {\n        &mut self.exec_manager","sourceCodeStart":2587,"sourceCodeEnd":2623,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/node/mod.rs#L2587-L2623","documentation":"set_cache_database only accepts a cache database adapter while the node is in the Idle state. Calling it after the node has begun starting/running is rejected to prevent mutating the cache backend while the node is live.","triggerScenarios":"Calling node.set_cache_database(...) after start/run has been initiated (state != NodeState::Idle), e.g. configuring the database inside a callback or after awaiting node start in async code.","commonSituations":"Reordering refactors that move configuration after the run call; conditional setup code that runs post-start; examples copied into code that already started the node.","solutions":["Move the set_cache_database call before node.run()/start() in the setup sequence","Check node.state() == NodeState::Idle before calling if the order is dynamic","Restructure so all kernel/adapter configuration happens in a single pre-run setup block"],"exampleFix":"// before\nnode.start().await?;\nnode.set_cache_database(db)?;\n// after\nnode.set_cache_database(db)?;\nnode.start().await?;","handlingStrategy":"validation","validationCode":"if node.state() == NodeState::Idle {\n    node.set_cache_database(db)?;\n} else {\n    return Err(anyhow::anyhow!(\"cache database must be set before node start\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Perform all adapter configuration in a single pre-run setup block","Check node.state() before any mutating configuration call","Never configure the node from inside running tasks/callbacks"],"tags":["rust","live-node","state","configuration","lifecycle"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}