{"record":{"id":"ae4f7e701f5a6613","repo":"nautechsystems/nautilus_trader","slug":"polymarket-rtds-task-owner-was-dropped","errorCode":null,"errorMessage":"Polymarket RTDS task owner was dropped","messagePattern":"Polymarket RTDS task owner was dropped","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/adapters/polymarket/src/rtds.rs","lineNumber":646,"sourceCode":"        }\n\n        self.inner.reconcile_pending.store(true, Ordering::Release);\n        self.ensure_reconcile_worker();\n        self.inner.reconcile_notify.notify_one();\n    }\n\n    pub(crate) async fn disconnect(&self) -> anyhow::Result<()> {\n        self.begin_shutdown();\n        let _guard = self.inner.wire_mutex.lock().await;\n\n        self.inner.reconcile_pending.store(false, Ordering::Release);\n        self.inner\n            .reset_live_state_pending\n            .store(false, Ordering::Release);\n        self.inner.reconcile_notify.notify_waiters();\n\n        let Some(tasks) = self.task_slots() else {\n            anyhow::bail!(\"Polymarket RTDS task owner was dropped\");\n        };\n        let mut ws = RtdsWebSocketGuard::take(&self.inner.ws_client);\n\n        if let Some(client) = ws.ws.as_ref() {\n            client.disconnect().await;\n        }\n\n        if let Some(control) = &self.inner.socket_control {\n            control.deregister();\n        }\n\n        self.inner.live_subscriptions.lock().clear();\n        drop(_guard);\n\n        let mut message_slot = tasks.message.lock().await;\n        if let Some(outcome) = finish_task(\n            &mut message_slot,\n            Duration::from_secs(2),","sourceCodeStart":628,"sourceCodeEnd":664,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/rtds.rs#L628-L664","documentation":"Raised during RTDS shutdown/teardown when the task-slot owner has already been dropped, so retained tasks cannot be finalized. The code clears the reset-live-state flag, notifies reconcilers, then bails because there is no task owner left to shut down. It signals a double shutdown or shutdown of an already-torn-down feed.","triggerScenarios":"Calling close/shutdown on the Polymarket RTDS feed when the RtdsTaskSlots owner was already dropped — a second close call, or close racing a completed teardown from another task.","commonSituations":"Calling disconnect/shutdown twice (e.g. from both a Drop impl and an explicit shutdown path); engine teardown invoking close on a feed whose supervisor already exited.","solutions":["Make shutdown idempotent: check whether task slots still exist before calling close.","Serialize shutdown calls (single closer task, JoinHandle, or a OnceLock-style flag).","Treat this error as 'already shut down' and ignore it in close paths.","Ensure exactly one component owns and closes the feed."],"exampleFix":"// before\nfeed.close().await?; // second call bails\nfeed.close().await?;\n// after\nif !feed.is_closed() {\n    feed.close().await?;\n}","handlingStrategy":"try-catch","validationCode":"if feed.is_closed() {\n    return Ok(()); // already shut down\n}","typeGuard":"fn needs_shutdown(feed: &PolymarketRtdsFeed) -> bool {\n    !feed.is_closed() && feed.task_slots().is_some()\n}","tryCatchPattern":"if let Err(e) = feed.close().await {\n    if e.to_string().contains(\"task owner was dropped\") {\n        log::debug!(\"already shut down\");\n    } else {\n        return Err(e);\n    }\n}","preventionTips":["Make shutdown idempotent and call it from exactly one place.","Use a OnceLock/flag so close cannot run twice.","Rely on Drop for teardown rather than mixing explicit and implicit close.","Ignore owner-dropped errors in close paths — they mean the work is done."],"tags":["websocket","shutdown","double-close","polymarket","lifecycle"],"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-14T00:17:10.932Z"}