{"record":{"id":"8f9c77dd6659b607","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-query-add-account-to-database-messa","errorCode":null,"errorMessage":"Failed to send query add_account to database message handler: {e}","messagePattern":"Failed to send query add_account to database message handler: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/cache.rs","lineNumber":944,"sourceCode":"\n    fn add_instrument_close(&self, close: &InstrumentClose) -> anyhow::Result<()> {\n        self.tx\n            .send(DatabaseQuery::AddInstrumentClose(*close))\n            .map_err(|e| {\n                anyhow::anyhow!(\n                    \"Failed to send query add_instrument_close to database message handler: {e}\"\n                )\n            })\n    }\n\n    fn add_synthetic(&self, _synthetic: &SyntheticInstrument) -> anyhow::Result<()> {\n        todo!()\n    }\n\n    fn add_account(&self, account: &AccountAny) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddAccount(account_last_event(account)?, false);\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to send query add_account to database message handler: {e}\")\n        })\n    }\n\n    fn add_order(&self, order: &OrderAny, client_id: Option<ClientId>) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddOrder(order_initialized_event(order), client_id);\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to send query add_order to database message handler: {e}\")\n        })\n    }\n\n    fn add_order_snapshot(&self, snapshot: &OrderSnapshot) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddOrderSnapshot(snapshot.to_owned());\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\n                \"Failed to send query add_order_snapshot to database message handler: {e}\"\n            )\n        })\n    }","sourceCodeStart":926,"sourceCodeEnd":962,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/cache.rs#L926-L962","documentation":"Thrown by `add_account` when the `DatabaseQuery::AddAccount` message cannot be sent to the database message-handler task because its receiver has been dropped. Note `account_last_event(account)` is evaluated first, so a SendError is the only source of this message. The account state is not persisted.","triggerScenarios":"Calling `add_account` (via `py_add_account`) when the writer task is gone: adapter stopped, handler panicked, or shutdown in progress.","commonSituations":"Persisting account updates after the SQL adapter disconnected; shutdown ordering issues in live deployments.","solutions":["Verify the adapter's background task is alive before writing accounts.","Look for receiver-task panics in logs.","Reconnect/recreate the adapter and retry.","In Python, wrap account persistence so it stops once the adapter is disconnected."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if not cache_db_adapter.is_running:\n    raise RuntimeError(\"Cannot add_account: adapter not running\")","typeGuard":null,"tryCatchPattern":"try:\n    cache.add_account(account)\nexcept RuntimeError as e:\n    logger.error(\"Account persistence failed (writer stopped): %s\", e)","preventionTips":["Persist account events while the adapter is connected","Close the cache database last during shutdown","Watch for handler-task panics in logs","Consider re-issuing the write after reconnect"],"tags":["database","channel","account","shutdown"],"backgroundTag":"database-write-failed","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"}