{"record":{"id":"67e54b1622b7d01f","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-order-cancel-rejected-event-e","errorCode":null,"errorMessage":"Failed to send order cancel rejected event: {e}","messagePattern":"Failed to send order cancel rejected event: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":1976,"sourceCode":"        ts_event: UnixNanos,\n        account_id: AccountId,\n    ) -> anyhow::Result<()> {\n        let event = OrderCancelRejected::new(\n            target_order.trader_id(),\n            target_order.strategy_id(),\n            target_order.instrument_id(),\n            target_order.client_order_id(),\n            Ustr::from(reason),\n            UUID4::new(),\n            ts_event,\n            ts_event,\n            false,\n            target_order.venue_order_id(),\n            Some(account_id),\n        );\n        exec_sender\n            .send(ExecutionEvent::Order(OrderEventAny::CancelRejected(event)))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send order cancel rejected event: {e}\"))\n    }\n}\n\n#[allow(dead_code)]\nimpl InteractiveBrokersExecutionClient {\n    fn parse_historical_fill_report(\n        &self,\n        cmd: &GenerateFillReports,\n        exec_data: &ExecutionData,\n        commission: f64,\n        commission_currency: &str,\n        ts_init: UnixNanos,\n    ) -> Option<FillReport> {\n        let instrument_id = match self.resolve_historical_execution_instrument_id(exec_data) {\n            Ok(instrument_id) => instrument_id,\n            Err(e) => {\n                Self::warn_historical_fill_report_parse_error(exec_data, &e);\n                return None;","sourceCodeStart":1958,"sourceCodeEnd":1994,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L1958-L1994","documentation":"`send_order_cancel_rejected` sends an `OrderEventAny::CancelRejected` event on the unbounded mpsc `exec_sender`. A send error means the receiving end has been closed; the anyhow wrapper reports that the cancel-rejected event could not be delivered.","triggerScenarios":"IB rejects a cancel request (e.g. order already filled or unknown to TWS) and, while emitting the CancelRejected event, the channel receiver has been dropped — event loop stopped or node shutdown in progress.","commonSituations":"Stale cancel for an already-filled order arriving at shutdown; racing teardown where the IB callback fires after the execution engine is dropped; duplicated cancel commands after reconnect.","solutions":["Order shutdown so the IB adapter is disconnected before the execution event loop is dropped.","Check for code issuing cancels after engine teardown and gate commands on node liveness.","If unavoidable at shutdown, handle the send error as a warning rather than a hard failure."],"exampleFix":"// before\nexec_sender\n    .send(ExecutionEvent::Order(OrderEventAny::CancelRejected(event)))\n    .map_err(|e| anyhow::anyhow!(\"Failed to send order cancel rejected event: {e}\"))\n// after\nexec_sender\n    .send(ExecutionEvent::Order(OrderEventAny::CancelRejected(event)))\n    .map_err(|e| anyhow::anyhow!(\"Failed to send order cancel rejected event: {e}\"))\n    .or_else(|e| { log::warn!(\"cancel rejected event dropped at shutdown: {e}\"); Ok::<(), anyhow::Error>(()) })","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// During teardown, downgrade send failures to warnings\nif exec_sender.send(ExecutionEvent::Order(OrderEventAny::CancelRejected(event))).is_err() {\n    log::warn!(\"cancel rejected event lost during shutdown\");\n}","preventionTips":["Avoid issuing cancels after initiating node shutdown.","Track pending cancels and drain them before stopping the event loop.","Deduplicate cancels for already-filled orders to reduce late rejections."],"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"}