{"record":{"id":"b0beba2bedaf986a","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-account-state-e-b0beba","errorCode":null,"errorMessage":"Failed to send account state: {e}","messagePattern":"Failed to send account state: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":529,"sourceCode":"        info: Option<Params>,\n    ) -> anyhow::Result<()> {\n        let factory = OrderEventFactory::new(\n            self.core.trader_id,\n            self.core.account_id,\n            self.core.account_type,\n            self.core.base_currency,\n        );\n        let state = factory.generate_account_state(\n            balances,\n            margins,\n            reported,\n            ts_event,\n            get_atomic_clock_realtime().get_time_ns(),\n            info,\n        );\n        get_exec_event_sender()\n            .send(ExecutionEvent::Account(state))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send account state: {e}\"))\n    }\n\n    fn start(&mut self) -> anyhow::Result<()> {\n        // Start is handled by connect() for live clients\n        Ok(())\n    }\n\n    fn stop(&mut self) -> anyhow::Result<()> {\n        self.begin_task_shutdown();\n        Ok(())\n    }\n\n    fn submit_order(&self, cmd: SubmitOrder) -> anyhow::Result<()> {\n        let order = self.core.get_order(&cmd.client_order_id)?;\n        if let Err(reason) = validate_order(&order) {\n            let reason = reason.to_string();\n            Self::send_order_denied(\n                cmd.order_init.trader_id,","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L511-L547","documentation":"generate_account_state builds an AccountState event and sends it through the shared execution event sender channel; if the channel send fails (receiver dropped or closed), the error is wrapped with anyhow::anyhow! into 'Failed to send account state: {e}'. This means the execution engine can no longer receive account updates, usually because the live execution engine has shut down or the channel was disconnected.","triggerScenarios":"A IB account summary/balance update arrives and generate_account_state tries send() on the ExecutionEvent channel while the receiving ExecutionEngine has been stopped, dropped, or its receiver disconnected.","commonSituations":"Shutting down a trading node while account subscription updates are still streaming in; an execution engine panic or disconnect closing the channel; race between client teardown and in-flight account events.","solutions":["Ensure the execution engine outlives the IB client or stop account subscriptions before tearing down the engine.","Check shutdown ordering in the trading node: unsubscribe/stop the data and execution clients before dropping the engine and its event channel.","Inspect logs preceding this error for engine panics or disconnects that closed the event channel unexpectedly."],"exampleFix":"// before\nget_exec_event_sender()\n    .send(ExecutionEvent::Account(state))\n    .map_err(|e| anyhow::anyhow!(\"Failed to send account state: {e}\"))\n// after\nmatch get_exec_event_sender().send(ExecutionEvent::Account(state)) {\n    Ok(()) => Ok(()),\n    Err(e) if e.is_disconnected() => {\n        tracing::debug!(\"Execution event channel closed; dropping account state update\");\n        Ok(())\n    }\n    Err(e) => Err(anyhow::anyhow!(\"Failed to send account state: {e}\")),\n}","handlingStrategy":"try-catch","validationCode":"fn event_channel_alive(sender: &Sender<ExecutionEvent>) -> bool {\n    !sender.is_closed()\n}","typeGuard":null,"tryCatchPattern":"match get_exec_event_sender().send(ExecutionEvent::Account(state)) {\n    Err(e) if e.is_disconnected() => tracing::debug!(\"Engine channel closed during shutdown\"),\n    Err(e) => return Err(anyhow::anyhow!(\"Failed to send account state: {e}\")),\n    Ok(()) => {}\n}","preventionTips":["Stop account subscriptions before shutting down the execution engine.","Keep the engine receiver alive as long as live clients may emit events.","Treat disconnected-channel errors during teardown as benign and log at debug level."],"tags":["channel","interactive-brokers","account-state","shutdown"],"backgroundTag":"broken-pipe","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"}