nautechsystems/nautilus_trader · error

Polymarket market pool shutdown failed: {}

Error message

Polymarket market pool shutdown failed: {}

What it means

During pool disconnect, each shard is shut down and any errors encountered while closing individual shards are collected. If any shard failed to shut down cleanly, disconnect aborts with this aggregate error listing all shutdown failures joined by semicolons.

Source

Thrown at crates/adapters/polymarket/src/websocket/pool.rs:364

                shard_failed = true;
                drain
                    .state
                    .shutdown_errors
                    .push(format!("market shard {shard_id} disconnect failed: {e}"));
            }

            if !shard_failed {
                drain.state.shards.remove(&shard_id);
                drain
                    .state
                    .assignments
                    .retain(|_, assigned_id| *assigned_id != shard_id);
            }
        }

        if !drain.state.shutdown_errors.is_empty() {
            let errors = std::mem::take(&mut drain.state.shutdown_errors);
            anyhow::bail!(
                "Polymarket market pool shutdown failed: {}",
                errors.join("; ")
            );
        }

        *self.inner.out_tx.lock() = None;
        *self.inner.out_rx.lock() = None;
        Ok(())
    }

    pub(crate) fn begin_shutdown(&self) {
        self.inner.begin_shutdown();
    }

    /// Clears retained reconnect-replay state on any remaining shards.
    pub(crate) fn clear_reconnect_state(&self) {
        let state = self.inner.state.lock();
        for shard in state.shards.values() {

View on GitHub (pinned to 18893faf8b)

Solutions

  1. Read the joined messages to identify which shards failed and why
  2. Retry disconnect() — many close failures are transient network conditions
  3. If connections are already dead, treat the pool as torn down and drop it; underlying resources will be released
  4. Check for stuck tasks/locks that prevent shard close from completing
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = pool.disconnect().await {
    // parse the joined shard errors; log and treat pool as torn down
    log::warn!("pool teardown errors: {e}");
}

Prevention

When it happens

Trigger: Calling disconnect() when one or more market shards fail to close (e.g., close_shard returns Err, underlying WebSocket send/close task fails), collected in drain.state.shutdown_errors.

Common situations: Shutting down a pool whose WebSocket connections already died or are unresponsive; network partitions at teardown; a shard task panicked or hung during close.

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


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/fb6b04429829c8d8. Report an issue: GitHub.