{"record":{"id":"34ecb3a9d3d74fde","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-query-update-order-to-database-mess","errorCode":null,"errorMessage":"Failed to send query update_order to database message handler: {e}","messagePattern":"Failed to send query update_order to database message handler: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/cache.rs","lineNumber":1275,"sourceCode":"    fn update_strategy(\n        &self,\n        strategy_id: &StrategyId,\n        _state: &AHashMap<String, Bytes>,\n    ) -> anyhow::Result<()> {\n        anyhow::bail!(\"update_strategy not implemented for PostgreSQL cache adapter: {strategy_id}\")\n    }\n\n    fn update_account(&self, account: &AccountAny) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddAccount(account_last_event(account)?, true);\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 update_order(&self, event: &OrderEventAny) -> anyhow::Result<()> {\n        let query = DatabaseQuery::UpdateOrder(event.clone());\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to send query update_order to database message handler: {e}\")\n        })\n    }\n\n    fn update_position(&self, position: &Position) -> anyhow::Result<()> {\n        let query = if position.fill_voids.is_empty() {\n            DatabaseQuery::UpdatePosition(position_last_event(position)?)\n        } else {\n            DatabaseQuery::AddPositionSnapshot(PositionSnapshot::from_replay_state(position, None))\n        };\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to send query update_position to database message handler: {e}\")\n        })\n    }\n\n    fn snapshot_order_state(&self, order: &OrderAny) -> anyhow::Result<()> {\n        let snapshot = OrderSnapshot::from(order.clone());\n        self.add_order_snapshot(&snapshot)\n    }","sourceCodeStart":1257,"sourceCodeEnd":1293,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/cache.rs#L1257-L1293","documentation":"update_order clones the OrderEventAny into DatabaseQuery::UpdateOrder and sends it over self.tx to the database message handler; a send failure is converted into this anyhow error. Failure implies the handler's receiver was dropped — the persistence task is gone. No order event has been written when this is raised.","triggerScenarios":"Calling update_order (or py_update_order) once the handler task has exited via shutdown, abort, or failed initialization.","commonSituations":"Order events arriving during teardown of the database adapter; handler panic from an earlier failing query; stale cache handles after a restart.","solutions":["Verify the adapter/handler is live before order event writes","Recreate the adapter instead of writing through a closed channel after shutdown","Find and fix why the handler died (logs)","In live trading, treat this as a persistence outage: buffer or persist events locally until the adapter is restored"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    cache.update_order(event)\nexcept Exception as e:\n    if \"Failed to send query update_order\" in str(e):\n        logger.error(\"order event persistence failed: handler down; buffering\")\n        pending_events.append(event)  # replay after adapter recovery","preventionTips":["Buffer order events locally when persistence is unavailable","Stop order processing before tearing down the database adapter","Rebuild adapter instances after reconnects; never write through stale ones","Watch handler task logs for early termination causes"],"tags":["rust","channel","database","postgres"],"backgroundTag":"broken-pipe","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}