{"record":{"id":"fb6b04429829c8d8","repo":"nautechsystems/nautilus_trader","slug":"polymarket-market-pool-shutdown-failed","errorCode":null,"errorMessage":"Polymarket market pool shutdown failed: {}","messagePattern":"Polymarket market pool shutdown failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/websocket/pool.rs","lineNumber":364,"sourceCode":"                shard_failed = true;\n                drain\n                    .state\n                    .shutdown_errors\n                    .push(format!(\"market shard {shard_id} disconnect failed: {e}\"));\n            }\n\n            if !shard_failed {\n                drain.state.shards.remove(&shard_id);\n                drain\n                    .state\n                    .assignments\n                    .retain(|_, assigned_id| *assigned_id != shard_id);\n            }\n        }\n\n        if !drain.state.shutdown_errors.is_empty() {\n            let errors = std::mem::take(&mut drain.state.shutdown_errors);\n            anyhow::bail!(\n                \"Polymarket market pool shutdown failed: {}\",\n                errors.join(\"; \")\n            );\n        }\n\n        *self.inner.out_tx.lock() = None;\n        *self.inner.out_rx.lock() = None;\n        Ok(())\n    }\n\n    pub(crate) fn begin_shutdown(&self) {\n        self.inner.begin_shutdown();\n    }\n\n    /// Clears retained reconnect-replay state on any remaining shards.\n    pub(crate) fn clear_reconnect_state(&self) {\n        let state = self.inner.state.lock();\n        for shard in state.shards.values() {","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/websocket/pool.rs#L346-L382","documentation":"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.","triggerScenarios":"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.","commonSituations":"Shutting down a pool whose WebSocket connections already died or are unresponsive; network partitions at teardown; a shard task panicked or hung during close.","solutions":["Read the joined messages to identify which shards failed and why","Retry disconnect() — many close failures are transient network conditions","If connections are already dead, treat the pool as torn down and drop it; underlying resources will be released","Check for stuck tasks/locks that prevent shard close from completing"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = pool.disconnect().await {\n    // parse the joined shard errors; log and treat pool as torn down\n    log::warn!(\"pool teardown errors: {e}\");\n}","preventionTips":["Retry disconnect on transient shutdown errors","Drop the pool if connections are already dead","Avoid disconnecting while shard tasks are hung","Monitor shard health so failures are known before teardown"],"tags":["websocket","polymarket","shutdown","cleanup"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}