nautechsystems/nautilus_trader · error
Failed to register Betfair cricket fatal task: {e}
Error message
Failed to register Betfair cricket fatal task: {e} What it means
Registering the cricket stream's fatal-error monitoring task failed; the underlying error `{e}` is re-wrapped. This watcher task detects fatal cricket-stream conditions and triggers reconnection/shutdown; connect aborts when it cannot be registered.
Source
Thrown at crates/adapters/betfair/src/data.rs:968
let cricket_socket_control =
self.cricket_socket_control.as_ref().map(Arc::clone);
self.session_tasks
.spawn(async move {
if cricket_fatal_rx.recv().await.is_some() {
log::error!(
"Betfair cricket stream permanently disabled due to fatal error"
);
cricket_client.close().await;
if let Some(control) = cricket_socket_control {
control.deregister();
}
}
})
.map_err(|e| {
anyhow::anyhow!("Failed to register Betfair cricket fatal task: {e}")
})?;
log::debug!("Betfair cricket stream connected");
}
Err(e) => {
log::warn!("Betfair cricket stream connect failed: {e}");
if let Some(control) = &self.cricket_socket_control {
control.deregister();
}
self.cricket_stream_client = None;
}
}
}
let keep_alive_client = Arc::clone(&self.http_client);
let keep_alive_stream = Arc::clone(self.stream_client.as_ref().unwrap());
let keep_alive_race_stream = self.race_stream_client.as_ref().map(Arc::clone);View on GitHub (pinned to 18893faf8b)
Solutions
- Inspect the inner `{e}` for the registration failure cause
- Avoid overlapping connect and disconnect calls on the same client
- Retry connect so the cricket stream and fatal watcher register within the same task-group generation
- If the cricket stream endpoint itself failed (logged as a warning), the fatal task registration should not be attempted — verify ordering
Defensive patterns
Strategy: try-catch
Validate before calling
// ensure no shutdown in progress before connect
if client.is_shutting_down() { return Err(anyhow::anyhow!("connect during shutdown")); } Try / catch
match client.connect().await {
Err(e) if e.to_string().contains("Failed to register Betfair cricket fatal task") => {
log::error!("cricket fatal watcher not registered: {e:#}");
// retry connect; ensure disconnect() isn't running concurrently
}
other => other,
} Prevention
- Avoid concurrent connect/disconnect on the same client
- Finish prior teardowns before reconnecting
- Retry connect to register the watcher within a single task-group generation
- Monitor cricket-stream connect warnings independently of registration errors
When it happens
Trigger: connect() -> after spawning the cricket stream task, the registration's map_err wraps a spawn/registration failure. Usually because the TaskGroup or shutdown registry is closed/not open due to a concurrent shutdown, or the group generation ended before registration completed.
Common situations: Connect racing disconnect; reconnect loop registering tasks into an already-advancing generation; internal spawn failure in the task group.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Failed to register Betfair race fatal task: {e}
- Failed to start AX execution session generation: {e}
- Failed to finish Betfair data session tasks: {e}
- Failed to start Betfair data session tasks: {e}
- Failed to start Betfair data command tasks: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/4acb8e1c555e9fd6.
Report an issue: GitHub.