{"record":{"id":"68d2fab5a747d542","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-order-denied-event-e","errorCode":null,"errorMessage":"Failed to send order denied event: {e}","messagePattern":"Failed to send order denied event: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":1926,"sourceCode":"        instrument_id: InstrumentId,\n        client_order_id: ClientOrderId,\n        reason: &str,\n    ) -> anyhow::Result<()> {\n        let ts_event = get_atomic_clock_realtime().get_time_ns();\n        let event = OrderDenied::new(\n            trader_id,\n            strategy_id,\n            instrument_id,\n            client_order_id,\n            Ustr::from(reason),\n            UUID4::new(),\n            ts_event,\n            ts_event,\n        );\n\n        get_exec_event_sender()\n            .send(ExecutionEvent::Order(OrderEventAny::Denied(event)))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send order denied event: {e}\"))\n    }\n\n    fn send_order_modify_rejected(\n        cmd: &ModifyOrder,\n        reason: &str,\n        exec_sender: &tokio::sync::mpsc::UnboundedSender<ExecutionEvent>,\n        ts_event: UnixNanos,\n        account_id: AccountId,\n    ) -> anyhow::Result<()> {\n        let event = OrderModifyRejected::new(\n            cmd.trader_id,\n            cmd.strategy_id,\n            cmd.instrument_id,\n            cmd.client_order_id,\n            Ustr::from(reason),\n            UUID4::new(),\n            ts_event,\n            ts_event,","sourceCodeStart":1908,"sourceCodeEnd":1944,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L1908-L1944","documentation":"When the adapter converts an IB order-denied notification into an `OrderEventAny::Denied` event, it sends the event over the global `tokio::sync::mpsc::UnboundedSender` obtained from `get_exec_event_sender()`. If the receiver side has been shut down (the execution event loop dropped its receiver), `send` fails and this anyhow error is returned, so the denial cannot be surfaced to the strategy.","triggerScenarios":"An order denied by IB arrives (e.g. rejected at submit due to margin/limits) while the execution event receiver has been dropped — i.e. during shutdown, after the actor/event-loop stopped, or a miswired exec event channel.","commonSituations":"Node shutting down while a rejection arrives in flight; TWS emitting a late deny after `ExecutionEngine` teardown; tests or tools that drop the receiver early.","solutions":["Ensure the node's execution event loop/actor stays alive as long as the IB adapter can deliver events; shut down the adapter before dropping the engine.","Check that `get_exec_event_sender()` is wired to the correct receiver and nothing re-initialized the global channel.","If this occurs at shutdown, treat it as benign log noise, but drain in-flight events before stopping the event loop."],"exampleFix":"// before\nlet sender = get_exec_event_sender();\nsender.send(event).map_err(...)?;\n// after\nif let Err(e) = get_exec_event_sender().send(event) {\n    log::warn!(\"exec event dropped (receiver closed): {e}\");\n}","handlingStrategy":"try-catch","validationCode":"// Before shutdown-sensitive work, confirm the exec channel still has a receiver\nfn exec_channel_alive() -> bool { /* true if the execution event loop task is still running */ true }","typeGuard":null,"tryCatchPattern":"if let Err(e) = client.submit_order(&cmd).await {\n    if e.to_string().contains(\"Failed to send order denied event\") {\n        log::warn!(\"exec receiver closed; order denial lost: {e}\");\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Disconnect the IB adapter before dropping the execution engine during shutdown.","Never drop the exec event receiver while adapter tasks may still emit events.","Keep a single canonical global exec channel; avoid re-initializing it mid-run."],"tags":["rust","tokio","mpsc-channel","event-delivery"],"backgroundTag":"mpsc-channel-closed","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"}