{"record":{"id":"13f59c02a297452e","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-order-pending-cancel-event-e","errorCode":null,"errorMessage":"Failed to send order pending cancel event: {e}","messagePattern":"Failed to send order pending cancel event: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/interactive_brokers/src/execution/core.rs","lineNumber":2429,"sourceCode":"        let (trader_id, strategy_id) =\n            Self::get_required_order_actor_ids(order_id, trader_id_map, strategy_id_map)?;\n\n        let event = OrderPendingCancel::new(\n            trader_id,\n            strategy_id,\n            instrument_id,\n            client_order_id,\n            Some(account_id),\n            UUID4::new(),\n            ts_init,\n            ts_init,\n            false,\n            Some(venue_order_id),\n        );\n\n        exec_sender\n            .send(ExecutionEvent::Order(OrderEventAny::PendingCancel(event)))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send order pending cancel event: {e}\"))?;\n\n        Ok(())\n    }\n}\n","sourceCodeStart":2411,"sourceCodeEnd":2434,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/interactive_brokers/src/execution/core.rs#L2411-L2434","documentation":"When a pending-cancel state is emitted, the adapter sends an `OrderEventAny::PendingCancel` event over the unbounded mpsc `exec_sender`. Failure means the receiver has been dropped, so the pending-cancel transition cannot be recorded and the error is wrapped and propagated out of the helper.","triggerScenarios":"The adapter emits PendingCancel (e.g. a cancel request was accepted/queued at IB) while the execution event receiver is closed — during node shutdown or if the channel wiring was torn down early.","commonSituations":"Cancel in flight at shutdown; IB acknowledging a cancel after the event loop stopped; tests/tools dropping the receiver before replaying queued events.","solutions":["Keep the execution event loop alive until the adapter is disconnected and all in-flight cancels settle.","Confirm the exec channel receiver is correctly registered before issuing cancels.","Treat the failure as non-fatal at teardown by logging a warning instead of aborting."],"exampleFix":"// before\nexec_sender\n    .send(ExecutionEvent::Order(OrderEventAny::PendingCancel(event)))\n    .map_err(|e| anyhow::anyhow!(\"Failed to send order pending cancel event: {e}\"))?;\n// after\nif let Err(e) = exec_sender.send(ExecutionEvent::Order(OrderEventAny::PendingCancel(event))) {\n    log::warn!(\"pending cancel event dropped (receiver closed): {e}\");\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = client.cancel_order(&cmd).await {\n    if e.to_string().contains(\"Failed to send order pending cancel event\") {\n        log::warn!(\"pending cancel event lost (receiver closed): {e}\");\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Keep the execution event loop running until all in-flight cancels reach a terminal state.","Disconnect the adapter only after the engine and its event receiver are still alive to consume final events.","Monitor shutdown logs for late PendingCancel/Denied events to tune teardown ordering."],"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"}