nautechsystems/nautilus_trader · critical
Failed to connect to Databento LSG: {e}
Error message
Failed to connect to Databento LSG: {e} What it means
This error is thrown by the Databento live streaming adapter when the initial or reconnecting call to establish the LSG (Live Streaming Gateway) client connection fails. The underlying Databento client error (authentication, network, DNS, subscription limits) is wrapped via anyhow::bail. It aborts run_session before any data is received.
Source
Thrown at crates/adapters/databento/src/live.rs:598
base.user_agent_extension(NAUTILUS_USER_AGENT.into())
.key(api_key.expose_secret().to_owned())?
.dataset(dataset)
.build()
.await
})
.await?;
let mut client = match result {
Ok(client) => {
if attempt > 1 {
log::info!("Reconnected successfully");
} else {
log::info!("Connected");
}
client
}
Err(e) => {
anyhow::bail!("Failed to connect to Databento LSG: {e}");
}
};
// Process any commands buffered during reconnection backoff
let mut start_buffered = false;
if !self.buffered_commands.is_empty() {
log::debug!(
"Processing {} buffered commands",
self.buffered_commands.len()
);
for cmd in self.buffered_commands.drain(..) {
match cmd {
HandlerCommand::Subscribe(sub) => {
if !self.replay && sub.start.is_some() {
self.replay = true;
}View on GitHub (pinned to 18893faf8b)
Solutions
- Verify the Databento API key is valid and has access to the configured dataset
- Check network connectivity and that the LSG host/port is reachable (no firewall/proxy block)
- Retry after checking Databento status page for outages
- Review the wrapped inner error {e} for the root cause (auth vs network)
Example fix
// before
client connect fails silently with generic key
api_key: Option<String>
// after
let api_key = std::env::var("DATABENTO_API_KEY")
.expect("DATABENTO_API_KEY must be set"); Defensive patterns
Strategy: retry
Validate before calling
let api_key = std::env::var("DATABENTO_API_KEY")?;
assert!(!api_key.is_empty()); Try / catch
match adapter.run().await {
Ok(_) => {},
Err(e) if e.to_string().contains("Failed to connect") => {
tokio::time::sleep(BACKOFF).await; // then retry
}
Err(e) => return Err(e),
} Prevention
- Validate the Databento API key at startup before going live
- Confirm dataset and subscription entitlements in the Databento dashboard
- Check network/firewall access to the LSG endpoint before deploying
- Monitor Databento status for maintenance windows
When it happens
Trigger: run_session calls client connect; the handshake returns Err — bad API key, unreachable gateway host, network outage, or Databento rejecting the dataset/subscription.
Common situations: Expired or invalid DATABENTO_API_KEY, no internet / DNS failure, wrong dataset id, firewall blocking the LSG port, Databento service maintenance windows.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- Session ended by gateway
- Connection error: {e}
- Reconnection timeout after {timeout_mins} minutes: {e}
- Failed to connect after {max_attempts} attempts
- Failed to connect to {} after {} attempts: {}. If this is a
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/5b6d5f4a35f021c3.
Report an issue: GitHub.