{"record":{"id":"05d15b71d66640d2","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-query-add-order-to-database-message","errorCode":null,"errorMessage":"Failed to send query add_order to database message handler: {e}","messagePattern":"Failed to send query add_order to database message handler: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/cache.rs","lineNumber":951,"sourceCode":"                )\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    }\n\n    fn add_position(&self, position: &Position) -> anyhow::Result<()> {\n        let event = position_last_event(position)?;\n        let query = DatabaseQuery::AddPosition(position.id, event);\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to send query add_position to database message handler: {e}\")\n        })","sourceCodeStart":933,"sourceCodeEnd":969,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/cache.rs#L933-L969","documentation":"Thrown by `add_order` when the `DatabaseQuery::AddOrder` message (the order's initialized event plus optional client_id) cannot be sent over the mpsc channel to the database message-handler task, i.e. the receiver was dropped. The order is not persisted.","triggerScenarios":"Calling `add_order` (via `py_add_order`) when the writer task has exited or panicked, so `tx.send` returns a SendError.","commonSituations":"Adding orders while the cache database adapter is stopping; handler thread crashed earlier in the session.","solutions":["Ensure the adapter is connected and its task running before adding orders.","Check logs for a panic in the message-handler task.","Reconnect/restart the adapter and retry the write.","Fix shutdown ordering so the cache database closes after trading logic."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if not cache_db_adapter.is_running:\n    raise RuntimeError(\"Cannot add_order: adapter not running\")","typeGuard":null,"tryCatchPattern":"try:\n    cache.add_order(order, client_id)\nexcept RuntimeError as e:\n    logger.error(\"Order persistence failed (writer stopped): %s\", e)","preventionTips":["Ensure the adapter is healthy before order submission flows","Never disconnect the cache database while trading is live","Alert on writer-task panics","Buffer orders for retry if the writer is down"],"tags":["database","channel","order","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"}