{"record":{"id":"78459c6eeab9ce20","repo":"nautechsystems/nautilus_trader","slug":"no-primary-market-shard-available-for-new-market-d","errorCode":null,"errorMessage":"No primary market shard available for new-market discovery","messagePattern":"No primary market shard available for new-market discovery","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/websocket/pool.rs","lineNumber":288,"sourceCode":"    ///\n    /// Returns an error if no primary shard is available.\n    pub async fn subscribe_new_markets_feed(&self) -> anyhow::Result<()> {\n        let _wire = self.inner.wire_mutex.lock().await;\n\n        let handle = {\n            let state = self.inner.state.lock();\n            if self.inner.closed.load(Ordering::Acquire) {\n                anyhow::bail!(\"Market connection pool is closed\");\n            }\n            state\n                .shards\n                .get(&PRIMARY_SHARD_ID)\n                .map(|shard| shard.handle.clone())\n        };\n\n        match handle {\n            Some(handle) => handle.subscribe_market(vec![]).await,\n            None => anyhow::bail!(\"No primary market shard available for new-market discovery\"),\n        }\n    }\n\n    /// Takes the merged message receiver, leaving `None` in its place.\n    #[must_use]\n    pub fn take_message_receiver(\n        &self,\n    ) -> Option<tokio::sync::mpsc::UnboundedReceiver<PolymarketWsMessage>> {\n        self.inner.out_rx.lock().take()\n    }\n\n    /// Disconnects every shard and clears routing state.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error after attempting every shard when a task or connection does not stop.\n    pub async fn disconnect(&self) -> anyhow::Result<()> {\n        self.inner.begin_shutdown();","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/websocket/pool.rs#L270-L306","documentation":"The Polymarket market connection pool maintains a designated 'primary' shard used for discovering newly listed markets (subscribing with an empty asset list). This error means no shard with PRIMARY_SHARD_ID exists in the pool when subscribe_new_markets_feed is called — either the pool has not connected yet or the primary shard was closed and not re-established.","triggerScenarios":"Calling subscribe_new_markets_feed before connect() has established the primary market shard, or after the primary shard was closed/removed by pool rebalancing without being reopened.","commonSituations":"Calling discovery subscription immediately after constructing the pool without connecting; a dropped WebSocket killed the primary shard and it was never restarted; calling the feed after disconnect.","solutions":["Ensure pool.connect() has completed successfully before calling subscribe_new_markets_feed","Reconnect the pool (call connect) to re-establish the primary shard, then retry the subscription","Check shard lifecycle: if the primary shard was closed by error/rebalance, verify connect_new_shard(PRIMARY_SHARD_ID) is invoked again","Guard the call by checking the pool's primary shard state before subscribing"],"exampleFix":"// before\nlet pool = MarketPool::new(config);\npool.subscribe_new_markets_feed().await?; // no primary shard yet\n// after\nlet pool = MarketPool::new(config);\npool.connect().await?; // establishes primary shard\npool.subscribe_new_markets_feed().await?;","handlingStrategy":"fallback","validationCode":"// ensure the primary shard exists before subscribing\nif pool.primary_shard_handle().is_none() {\n    pool.connect().await?;\n}","typeGuard":null,"tryCatchPattern":"match pool.subscribe_new_markets_feed().await {\n    Ok(rx) => { /* use feed */ }\n    Err(e) if e.to_string().contains(\"No primary market shard\") => {\n        pool.connect().await?;\n        pool.subscribe_new_markets_feed().await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always call connect() before any subscribe API","Reconnect the pool after observed shard closures","Treat discovery subscription as dependent on primary shard health","Monitor shard connectivity in long-running sessions"],"tags":["websocket","polymarket","connection-state","initialization-order"],"backgroundTag":"resource-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}