nautechsystems/nautilus_trader · error · anyhow::Error
Failed to start Polymarket task generation: {e}
Error message
Failed to start Polymarket task generation: {e} What it means
connect_client calls tasks.start_generation() when the task group is not open. If that call fails (task group cannot begin a new admission generation, e.g. it is in a bad shutdown state or the underlying runtime facility is unavailable), this error propagates out of connect().
Source
Thrown at crates/adapters/polymarket/src/data/lifecycle.rs:510
}
pub(super) async fn connect_client(&mut self) -> anyhow::Result<()> {
if self.is_connected() && self.tasks.is_open() && !self.reset_pending {
return Ok(());
}
if self.reset_pending
|| !self.tasks.is_empty()
|| !self.tasks.is_open()
|| self.ws_client.connection_count() > 0
{
self.disconnect_client().await?;
}
if !self.tasks.is_open() {
self.tasks
.start_generation()
.map_err(|e| anyhow::anyhow!("Failed to start Polymarket task generation: {e}"))?;
self.cancellation_token = self.tasks.cancellation_token();
}
let ws_client = self.ws_client.handle();
let rtds_feed = self.rtds_feed.clone();
let setup_guard = TaskGroupGuard::new(&[&self.tasks], move || {
ws_client.begin_shutdown();
rtds_feed.begin_shutdown();
});
self.ensure_position_event_subscription();
register_polymarket_custom_data();
log::info!("Connecting Polymarket data client");
log::debug!("Bootstrapping instruments from Gamma API...");
self.bootstrap_instruments().await?;
log::debug!(
"Bootstrap complete, {} instruments loaded",View on GitHub (pinned to 18893faf8b)
Solutions
- Wait for the previous disconnect to fully complete (including task termination) before reconnecting
- Construct a fresh client instance if the previous generation failed to close cleanly
- Increase disconnect timeout to avoid leaving the group half-shut-down
- Ensure the tokio runtime is healthy and not being torn down
Defensive patterns
Strategy: retry
Try / catch
let client = match client.connect().await {
Err(e) if e.to_string().contains("task generation") => {
warn!("generation start failed; rebuilding client");
let mut c = build_client(cfg)?;
c.connect().await?;
c
}
_ => client,
}; Prevention
- Let a timed-out disconnect fully drain before reconnecting (wait grace period)
- Increase disconnect timeouts to avoid half-shutdown groups
- Rebuild the client instance when start_generation repeatedly fails
When it happens
Trigger: Calling connect()/connect on a client whose task group fails start_generation() — group wedged mid-shutdown, or spawner infrastructure reporting closure.
Common situations: Reconnecting a client immediately after a failed/aborted disconnect; disconnect that timed out (see 'Failed to terminate Polymarket data tasks') leaving the group in a partial shutdown state; process teardown in progress.
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
- Command receiver already taken
- Failed to start Betfair data session tasks: {e}
- Failed to start Betfair data command tasks: {e}
- Failed to start Betfair session generation: {e}
- Failed to start Betfair task generation: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/a0efdf56b1c653c6.
Report an issue: GitHub.