{"record":{"id":"e2b856d0b0837aeb","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-order-rejected-event-e-e2b856","errorCode":null,"errorMessage":"Failed to send order rejected event: {e}","messagePattern":"Failed to send order rejected event: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core_updates.rs","lineNumber":1103,"sourceCode":"            .unwrap_or_else(|_| format!(\"whatIf analysis for order {}\", order_data.order_id));\n\n        let event = OrderRejected::new(\n            trader_id,\n            strategy_id,\n            instrument_id,\n            client_order_id,\n            account_id,\n            Ustr::from(&reason_json),\n            UUID4::new(),\n            ts_init,\n            ts_init,\n            false,\n            false,\n        );\n\n        exec_sender\n            .send(ExecutionEvent::Order(OrderEventAny::Rejected(event)))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send order rejected event: {e}\"))?;\n\n        tracing::debug!(\n            \"What-if analysis completed for order {}: margin change={:?}, commission={:?}\",\n            client_order_id,\n            order_data\n                .order_state\n                .initial_margin_after\n                .and_then(|after| order_data\n                    .order_state\n                    .initial_margin_before\n                    .map(|before| after - before)),\n            order_data.order_state.commission\n        );\n\n        Ok(())\n    }\n\n    #[allow(clippy::too_many_arguments)]","sourceCodeStart":1085,"sourceCodeEnd":1121,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core_updates.rs#L1085-L1121","documentation":"After a what-if order analysis completes, the adapter builds an OrderRejected/Denied event and sends it through the exec_sender channel. The send fails when the execution event receiver has been dropped, meaning the engine consuming events is gone while the IB what-if response is being processed.","triggerScenarios":"handle_whatif_order receives an OpenOrder/OrderState for a what-if order, emits OrderEventAny::Rejected via exec_sender.send, and the channel receiver is closed.","commonSituations":"Engine/node shut down while what-if results stream back; consumer task died from an earlier fault; adapter still subscribed after teardown.","solutions":["Keep the execution engine/event consumer running until IB what-if responses are drained or the adapter disconnects.","Stop what-if requests and adapter subscriptions before shutting down the event receiver.","Log send failures during shutdown rather than treating them as fatal."],"exampleFix":"// before\nexec_sender\n    .send(ExecutionEvent::Order(OrderEventAny::Rejected(event)))\n    .map_err(|e| anyhow::anyhow!(\"Failed to send order rejected event: {e}\"))?;\n// after\nif let Err(e) = exec_sender.send(ExecutionEvent::Order(OrderEventAny::Rejected(event))) {\n    tracing::warn!(\"Execution channel closed, dropping what-if rejected event: {e}\");\n}","handlingStrategy":"try-catch","validationCode":"// Rust: only send what-if events while the channel is open\nif exec_sender.is_closed() {\n    tracing::warn!(\"Channel closed; what-if rejected event dropped\");\n    return Ok(());\n}","typeGuard":"fn channel_open(sender: &mpsc::Sender<ExecutionEvent>) -> bool {\n    !sender.is_closed()\n}","tryCatchPattern":"if let Err(e) = exec_sender.send(ExecutionEvent::Order(OrderEventAny::Rejected(event))) {\n    tracing::warn!(\"What-if rejected event dropped: {e}\");\n    return Ok(());\n}","preventionTips":["Await what-if responses before shutting down the execution engine","Cancel outstanding what-if requests on disconnect","Treat post-shutdown send failures as warnings, not errors"],"tags":["channel","messaging","shutdown","what-if","rust"],"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"}