nautechsystems/nautilus_trader · warning
Polymarket data shutdown failed: {}
Error message
Polymarket data shutdown failed: {} What it means
During Polymarket data-client shutdown, errors accumulated from closing streams/tasks are joined and returned as a single anyhow error prefixed 'Polymarket data shutdown failed:'. disconnect_client surfaces all shutdown problems instead of failing on the first.
Source
Thrown at crates/adapters/polymarket/src/data/lifecycle.rs:633
self.config.transport_backend,
self.clock,
self.data_sender.clone(),
self.proxy_url.clone(),
self.rtds_socket_control.clone(),
);
self.reset_pending = false;
}
self.is_connected
.store(false, std::sync::atomic::Ordering::Relaxed);
log::info!("Disconnected Polymarket data client");
}
if self.shutdown_errors.is_empty() {
Ok(())
} else {
let errors = std::mem::take(&mut self.shutdown_errors);
anyhow::bail!("Polymarket data shutdown failed: {}", errors.join("; "))
}
}
}
#[cfg(test)]
mod tests {
use std::{
cell::RefCell,
rc::Rc,
sync::{Arc, atomic::Ordering},
};
use nautilus_common::{
cache::Cache,
clients::{DataClient, ExecutionClient},
clock::{Clock, TestClock},
live::runner::{replace_data_event_sender, replace_exec_event_sender},
messages::{View on GitHub (pinned to 18893faf8b)
Solutions
- Read the joined error message to see which shutdown step failed; each sub-error is separated by '; '
- Ensure the client is connected before disconnecting; guard against double disconnect in application code
- If caused by network loss at shutdown, treat as benign but verify no reconnect loop is fighting the shutdown
- Check logs around shutdown for the originating task/stream errors
Defensive patterns
Strategy: try-catch
Validate before calling
if !client.is_connected() {
log::info!("client already disconnected; skipping shutdown");
return Ok(());
} Try / catch
if let Err(e) = client.disconnect().await {
log::warn!("shutdown issues (usually benign on network loss): {e}");
// inspect joined sub-errors, ensure no reconnect loop active
} Prevention
- Avoid double-disconnect by tracking connection state
- Ensure no background reconnect tasks are running during shutdown
- Log full joined error to identify the failing shutdown step
When it happens
Trigger: Calling disconnect (or a failed connect_client cleanup) when one or more shutdown steps (WS stream close, task abort, subscription cleanup) recorded errors into self.shutdown_errors.
Common situations: Network already down when closing WebSockets; underlying tasks already panicked/finished; double disconnect where streams are already closed.
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
- RTDS task owner was dropped
- Polymarket RTDS task owner was dropped
- RTDS connection was canceled by shutdown
- Polymarket market pool shutdown failed: {}
- {errors.join("; ")}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/9d9fd778aeb9c5fc.
Report an issue: GitHub.