nautechsystems/nautilus_trader · error · anyhow::Error

Failed to send order pending cancel event

Error message

Failed to send order pending cancel event: {e}

What it means

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.

Solutions

  1. Keep the execution event loop alive until the adapter is disconnected and all in-flight cancels settle.
  2. Confirm the exec channel receiver is correctly registered before issuing cancels.
  3. Treat the failure as non-fatal at teardown by logging a warning instead of aborting.

Example fix

// before
exec_sender
    .send(ExecutionEvent::Order(OrderEventAny::PendingCancel(event)))
    .map_err(|e| anyhow::anyhow!("Failed to send order pending cancel event: {e}"))?;
// after
if let Err(e) = exec_sender.send(ExecutionEvent::Order(OrderEventAny::PendingCancel(event))) {
    log::warn!("pending cancel event dropped (receiver closed): {e}");
}
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = client.cancel_order(&cmd).await {
    if e.to_string().contains("Failed to send order pending cancel event") {
        log::warn!("pending cancel event lost (receiver closed): {e}");
    } else {
        return Err(e);
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: Cancel in flight at shutdown; IB acknowledging a cancel after the event loop stopped; tests/tools dropping the receiver before replaying queued events.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/13f59c02a297452e. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/interactive_brokers/src/execution/core.rs:2429

        let (trader_id, strategy_id) =
            Self::get_required_order_actor_ids(order_id, trader_id_map, strategy_id_map)?;

        let event = OrderPendingCancel::new(
            trader_id,
            strategy_id,
            instrument_id,
            client_order_id,
            Some(account_id),
            UUID4::new(),
            ts_init,
            ts_init,
            false,
            Some(venue_order_id),
        );

        exec_sender
            .send(ExecutionEvent::Order(OrderEventAny::PendingCancel(event)))
            .map_err(|e| anyhow::anyhow!("Failed to send order pending cancel event: {e}"))?;

        Ok(())
    }
}

View on GitHub (pinned to 18893faf8b)