{"record":{"id":"3428fb7871b8e744","repo":"nautechsystems/nautilus_trader","slug":"failed-to-replay-subscribeuser-e","errorCode":null,"errorMessage":"Failed to replay SubscribeUser: {e}","messagePattern":"Failed to replay SubscribeUser: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/websocket/client.rs","lineNumber":317,"sourceCode":"            WsChannel::Market => {\n                let topics = self.subscriptions.reset_after_reconnect();\n                if !topics.is_empty() || self.discovery_subscribed.load(Ordering::Relaxed) {\n                    log::debug!(\n                        \"Replaying market subscription state onto new session: assets={}, discovery={}\",\n                        topics.len(),\n                        self.discovery_subscribed.load(Ordering::Relaxed),\n                    );\n                    Some((topics, connection_epoch))\n                } else {\n                    None\n                }\n            }\n            WsChannel::User => {\n                if self.user_subscribed.load(Ordering::Relaxed) {\n                    log::debug!(\"Replaying user subscribe onto new session\");\n                    cmd_tx\n                        .send(HandlerCommand::SubscribeUser)\n                        .map_err(|e| anyhow::anyhow!(\"Failed to replay SubscribeUser: {e}\"))?;\n                }\n                None\n            }\n        };\n\n        let signal = Arc::clone(&self.signal);\n        let channel = self.channel;\n        let credential = self.credential.clone();\n        let subscriptions = self.subscriptions.clone();\n        let discovery_subscribed = Arc::clone(&self.discovery_subscribed);\n        let auth_tracker = self.auth_tracker.clone();\n        let user_subscribed = self.user_subscribed.load(Ordering::Relaxed);\n        let subscribe_new_markets = self.subscribe_new_markets;\n\n        if let Err(e) = self.task_handle.spawn(async move {\n            let mut handler = FeedHandler::new(\n                signal,\n                channel,","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/websocket/client.rs#L299-L335","documentation":"On reconnect, connect() replays a previously established user-channel subscription by sending HandlerCommand::SubscribeUser to the freshly spawned handler task's command channel. This error means that send failed — the new handler task's receiver was already gone, i.e. the newly started handler exited immediately (spawn failure or instant panic/error), so the user subscription could not be restored on the new session.","triggerScenarios":"A reconnect where the just-spawned handler task dies before consuming commands — e.g. the WebSocket endpoint refuses the new connection repeatedly, the handler panics during startup, or the task is cancelled right after spawn.","commonSituations":"Flaky network or gateway outage during reconnect; auth credentials revoked so the handler exits on first auth attempt; calling connect() in a loop that cancels tasks faster than they can run.","solutions":["Retry connect() after a short backoff — a transient spawn/connect failure often succeeds on the next attempt","Verify auth credentials (API key/secret/passphrase) are still valid, since handler startup failures commonly stem from auth","Check handler task logs/panic output for the immediate-exit cause","After a successful connect(), confirm user_subscribed state matches reality and re-issue subscribe_user() if needed"],"exampleFix":"// before\nclient.connect().await?; // replay may fail if handler dies instantly\n// after\nfor attempt in 0..3 {\n    match client.connect().await {\n        Ok(()) => break,\n        Err(e) if attempt < 2 => tokio::time::sleep(Duration::from_millis(250 * (1 << attempt))).await,\n        Err(e) => return Err(e),\n    }\n}","handlingStrategy":"retry","validationCode":"// validate auth material before reconnect so the handler does not die at startup\nif api_key.is_empty() || api_secret.is_empty() {\n    return Err(anyhow::anyhow!(\"credentials required for user channel replay\"));\n}","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"Failed to replay SubscribeUser\") => {\n        tokio::time::sleep(Duration::from_millis(500)).await;\n        client.connect().await?; // retry: fresh handler may survive\n    }\n    other => other?,\n}","preventionTips":["Use bounded exponential backoff around connect() for reconnects","Keep API credentials valid/rotated — startup auth failures kill the fresh handler instantly","Avoid connect() loops that spawn and cancel handlers faster than they initialize","After reconnect, verify user_subscribed state and re-issue subscribe_user() if needed"],"tags":["rust","websocket","reconnect","channel","polymarket"],"backgroundTag":"channel-closed","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"}