{"record":{"id":"7595eb8499196f31","repo":"nautechsystems/nautilus_trader","slug":"polymarket-rtds-task-shutdown-failed","errorCode":null,"errorMessage":"Polymarket RTDS task shutdown failed: {}","messagePattern":"Polymarket RTDS task shutdown failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/rtds.rs","lineNumber":132,"sourceCode":"        if self.ws.is_some() {\n            *self.owner.lock() = self.ws.take();\n        }\n    }\n}\n\nimpl RtdsTaskSlots {\n    fn push_shutdown_error(&self, error: String) {\n        self.shutdown_errors.lock().push(error);\n    }\n\n    fn take_shutdown_result(&self) -> anyhow::Result<()> {\n        let mut errors = self.shutdown_errors.lock();\n\n        if errors.is_empty() {\n            Ok(())\n        } else {\n            let errors = std::mem::take(&mut *errors);\n            anyhow::bail!(\n                \"Polymarket RTDS task shutdown failed: {}\",\n                errors.join(\"; \")\n            )\n        }\n    }\n}\n\nimpl Drop for RtdsTaskSlots {\n    fn drop(&mut self) {\n        self.message.get_mut().abort();\n        self.reconcile.get_mut().abort();\n    }\n}\n\n#[derive(Debug)]\nstruct PolymarketRtdsFeedInner {\n    url: String,\n    proxy_url: Option<ProxyUrl>,","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/rtds.rs#L114-L150","documentation":"take_shutdown_result collects per-task shutdown errors recorded during RTDS teardown; if any exist, it joins them and fails. The RTDS (real-time data stream) background tasks reported failures while stopping, so shutdown did not complete cleanly.","triggerScenarios":"Calling shutdown/take_shutdown_result when one or more RTDS tasks (websocket, reconcile workers) errored during cancellation — e.g. write-after-close on the socket, task panicked, or channel send failed during teardown.","commonSituations":"Abrupt network loss at shutdown time; dropping the client while tasks are mid-message; platform-specific socket close races.","solutions":["Inspect the joined error messages after this error to identify which task failed","Ensure shutdown is awaited and the client is not dropped concurrently while tasks run","Retry shutdown once tasks have settled; if transient network noise, it is usually safe after confirming sockets are closed"],"exampleFix":"// before\ndrop(client); // tasks shut down with errors, surfaced later\n// after\nclient.shutdown().await?; // logs per-task errors, cleans shutdown","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.shutdown().await {\n    Err(e) if e.to_string().starts_with(\"Polymarket RTDS task shutdown failed\") => {\n        log::warn!(\"RTDS shutdown errors: {e}\"); // usually benign during teardown\n    }\n    r => r?,\n}","preventionTips":["Always await shutdown instead of dropping the client mid-stream","Avoid concurrent calls to connect/shutdown","Keep network stability in mind during teardown; log rather than panic"],"tags":["rust","shutdown","websocket","async"],"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"}