nautechsystems/nautilus_trader · error · anyhow::Error

Failed to send account state: {e}

Error message

Failed to send account state: {e}

What it means

try_send_account_state found an initialized sender but the channel send failed because the receiver has been closed/dropped. The underlying channel error is embedded in the message. It means the execution event consumer is gone when an account state update is delivered.

Source

Thrown at crates/live/src/execution/emitter.rs:502

    pub fn send_account_state(&self, state: AccountState) {
        if let Err(e) = self.try_send_account_state(state) {
            log::warn!("{e}");
        }
    }

    /// Emits an account state event and returns any channel error to the caller.
    ///
    /// # Errors
    ///
    /// Returns an error if the sender is uninitialized or its receiver is closed.
    pub fn try_send_account_state(&self, state: AccountState) -> anyhow::Result<()> {
        let sender = self.sender.load();
        let sender = sender
            .as_ref()
            .ok_or_else(|| anyhow::anyhow!("Cannot send account state: sender not initialized"))?;
        sender
            .send(ExecutionEvent::Account(state))
            .map_err(|e| anyhow::anyhow!("Failed to send account state: {e}"))
    }

    /// Emits an execution report.
    pub fn send_execution_report(&self, report: ExecutionReport) {
        if let Err(e) = self.try_send_execution_report(report) {
            log::warn!("{e}");
        }
    }

    /// Emits an execution report and returns any channel error to the caller.
    ///
    /// # Errors
    ///
    /// Returns an error if the sender is not initialized or the receiving channel is closed.
    pub fn try_send_execution_report(&self, report: ExecutionReport) -> anyhow::Result<()> {
        let sender = self.sender.load();
        let sender = sender.as_ref().ok_or_else(|| {
            anyhow::anyhow!("Cannot send execution report: sender not initialized")

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Stop account-state emissions once shutdown has begun.
  2. Retry the emission after reconnect when a fresh receiver exists.
  3. Treat as non-fatal during teardown and log at warn level.
  4. Read the wrapped channel error to confirm receiver-closed semantics.

Example fix

// before
emitter.try_send_account_state(state)?;
// after
if let Err(e) = emitter.try_send_account_state(state) {
    log::warn!("account state not delivered (receiver closed?): {e}");
}
Defensive patterns

Strategy: retry

Try / catch

if let Err(e) = emitter.try_send_account_state(state) { log::warn!("account state undelivered: {e}"); // re-emit after reconnect }

Prevention

When it happens

Trigger: Sending an account state after the execution engine (channel receiver) was stopped — node shutdown, engine restart, or a crashed consumer task closing the channel.

Common situations: Periodic account-state reconciliation timers firing after shutdown started; reconnect recovery re-emitting account state while the engine task is being replaced.

Related errors


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