{"record":{"id":"0546db199c1b5754","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-query-add-instrument-close-to-datab","errorCode":null,"errorMessage":"Failed to send query add_instrument_close to database message handler: {e}","messagePattern":"Failed to send query add_instrument_close to database message handler: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/cache.rs","lineNumber":931,"sourceCode":"    fn add_currency(&self, currency: &Currency) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddCurrency(*currency);\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to query add_currency to database message handler: {e}\")\n        })\n    }\n\n    fn add_instrument(&self, instrument: &InstrumentAny) -> anyhow::Result<()> {\n        let query = DatabaseQuery::AddInstrument(instrument.clone());\n        self.tx.send(query).map_err(|e| {\n            anyhow::anyhow!(\"Failed to send query add_instrument to database message handler: {e}\")\n        })\n    }\n\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);","sourceCodeStart":913,"sourceCodeEnd":949,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/cache.rs#L913-L949","documentation":"Thrown by `add_instrument_close` when sending `DatabaseQuery::AddInstrumentClose` to the database message-handler task fails because the receiving end of the channel has been dropped. The instrument close is not persisted.","triggerScenarios":"Calling `add_instrument_close` after the writer task shut down or its thread panicked, making `tx.send` return a SendError.","commonSituations":"Persisting instrument closes during teardown; a crashed writer task in a long-running session.","solutions":["Keep the cache database adapter running until all writes complete.","Check for panics in the message-handler task.","Restart/reconnect the adapter and re-issue the write.","Sequence shutdown so the cache is closed last."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if not cache_db_adapter.is_running:\n    raise RuntimeError(\"Cannot add_instrument_close: adapter not running\")","typeGuard":null,"tryCatchPattern":"try:\n    cache.add_instrument_close(close)\nexcept RuntimeError as e:\n    logger.error(\"Instrument close persistence failed: %s\", e)","preventionTips":["Write instrument closes before adapter shutdown","Monitor writer task liveness","Persist closes immediately when produced, not during teardown","Retry after adapter reconnect"],"tags":["database","channel","instrument","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-14T00:17:10.932Z"}