{"record":{"id":"4c667e89ad4935d8","repo":"nautechsystems/nautilus_trader","slug":"failed-to-send-setclient-command-e","errorCode":null,"errorMessage":"Failed to send SetClient command: {e}","messagePattern":"Failed to send SetClient command: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/coinbase/src/websocket/client.rs","lineNumber":296,"sourceCode":"            .config(cfg)\n            .message_handler(message_handler)\n            .keyed_quotas(keyed_quotas)\n            .default_quota(*COINBASE_WS_CONNECTION_QUOTA)\n            .maybe_state_sink(self.socket_control.as_ref().map(SocketControl::sink))\n            .connect()\n            .await?;\n\n        let (cmd_tx, cmd_rx) = tokio::sync::mpsc::unbounded_channel::<HandlerCommand>();\n        let (out_tx, out_rx) = tokio::sync::mpsc::unbounded_channel::<NautilusWsMessage>();\n\n        *self.cmd_tx.write().await = cmd_tx.clone();\n        self.out_rx = Some(out_rx);\n        self.connection_mode.store(client.connection_mode_atomic());\n        let reconnect_handle = client.reconnect_handle();\n        log::debug!(\"Coinbase WebSocket connected: {}\", self.url);\n\n        if let Err(e) = cmd_tx.send(HandlerCommand::SetClient(client)) {\n            anyhow::bail!(\"Failed to send SetClient command: {e}\");\n        }\n\n        if let Some(control) = &self.socket_control {\n            control.register(move || reconnect_handle.request_reconnect());\n        }\n\n        let instruments_vec: Vec<InstrumentAny> =\n            self.instruments.load().values().cloned().collect();\n\n        if !instruments_vec.is_empty()\n            && let Err(e) = cmd_tx.send(HandlerCommand::InitializeInstruments(instruments_vec))\n        {\n            log::error!(\"Failed to send InitializeInstruments: {e}\");\n        }\n\n        // Restore bar type registrations from previous session\n        for (key, bar_type) in &self.bar_types {\n            if let Err(e) = cmd_tx.send(HandlerCommand::AddBarType {","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/coinbase/src/websocket/client.rs#L278-L314","documentation":"After establishing the WebSocket connection, connect() injects the freshly built client into the running handler task via a HandlerCommand::SetClient message on a channel. If that send fails (receiver dropped), the adapter cannot hand off the authenticated client and bails with this error.","triggerScenarios":"The handler task exited/closed its command channel before SetClient was sent — usually because the handler died immediately after spawn (e.g. connection dropped, panic) while connect() was still setting up.","commonSituations":"WebSocket server accepted then immediately closed the connection; handler panicked during initialization; rapid reconnect storm closed the channel between iterations.","solutions":["Check the handler logs just before this error for the underlying disconnect cause","Verify network stability to the Coinbase WebSocket endpoint","Retry the connection; if recurring, ensure only one connect loop owns the client lifecycle"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match ws.connect().await {\n    Err(e) if e.to_string().contains(\"Failed to send SetClient\") => {\n        log::warn!(\"handler died during setup, retrying: {e}\");\n        // reconnect with backoff\n    }\n    other => other.map(|_| ()),\n}","preventionTips":["Check endpoint reachability/health before connect","Investigate handler logs for the primary failure preceding this symptom","Serialize reconnect attempts with backoff"],"tags":["rust","coinbase","websocket","channel"],"backgroundTag":"broken-pipe","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"}