nautechsystems/nautilus_trader · error
Failed to send query add_order to database message handler:
Error message
Failed to send query add_order to database message handler: {e} What it means
Thrown by `add_order` when the `DatabaseQuery::AddOrder` message (the order's initialized event plus optional client_id) cannot be sent over the mpsc channel to the database message-handler task, i.e. the receiver was dropped. The order is not persisted.
Source
Thrown at crates/infrastructure/src/sql/cache.rs:951
)
})
}
fn add_synthetic(&self, _synthetic: &SyntheticInstrument) -> anyhow::Result<()> {
todo!()
}
fn add_account(&self, account: &AccountAny) -> anyhow::Result<()> {
let query = DatabaseQuery::AddAccount(account_last_event(account)?, false);
self.tx.send(query).map_err(|e| {
anyhow::anyhow!("Failed to send query add_account to database message handler: {e}")
})
}
fn add_order(&self, order: &OrderAny, client_id: Option<ClientId>) -> anyhow::Result<()> {
let query = DatabaseQuery::AddOrder(order_initialized_event(order), client_id);
self.tx.send(query).map_err(|e| {
anyhow::anyhow!("Failed to send query add_order to database message handler: {e}")
})
}
fn add_order_snapshot(&self, snapshot: &OrderSnapshot) -> anyhow::Result<()> {
let query = DatabaseQuery::AddOrderSnapshot(snapshot.to_owned());
self.tx.send(query).map_err(|e| {
anyhow::anyhow!(
"Failed to send query add_order_snapshot to database message handler: {e}"
)
})
}
fn add_position(&self, position: &Position) -> anyhow::Result<()> {
let event = position_last_event(position)?;
let query = DatabaseQuery::AddPosition(position.id, event);
self.tx.send(query).map_err(|e| {
anyhow::anyhow!("Failed to send query add_position to database message handler: {e}")
})View on GitHub (pinned to 18893faf8b)
Solutions
- Ensure the adapter is connected and its task running before adding orders.
- Check logs for a panic in the message-handler task.
- Reconnect/restart the adapter and retry the write.
- Fix shutdown ordering so the cache database closes after trading logic.
Defensive patterns
Strategy: try-catch
Validate before calling
if not cache_db_adapter.is_running:
raise RuntimeError("Cannot add_order: adapter not running") Try / catch
try:
cache.add_order(order, client_id)
except RuntimeError as e:
logger.error("Order persistence failed (writer stopped): %s", e) Prevention
- Ensure the adapter is healthy before order submission flows
- Never disconnect the cache database while trading is live
- Alert on writer-task panics
- Buffer orders for retry if the writer is down
When it happens
Trigger: Calling `add_order` (via `py_add_order`) when the writer task has exited or panicked, so `tx.send` returns a SendError.
Common situations: Adding orders while the cache database adapter is stopping; handler thread crashed earlier in the session.
Related errors
- Failed to send query to database message handler: {e}
- Failed to query add_currency to database message handler: {e
- Failed to send query add_instrument to database message hand
- Failed to send query add_instrument_close to database messag
- Failed to send query add_account to database message handler
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/05d15b71d66640d2.
Report an issue: GitHub.