{"record":{"id":"39f4ef3d6878ff72","repo":"nautechsystems/nautilus_trader","slug":"no-active-websocket-client-39f4ef","errorCode":null,"errorMessage":"No active WebSocket client","messagePattern":"No active WebSocket client","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/bitmex/src/websocket/handler.rs","lineNumber":121,"sourceCode":"                    || {\n                        let payload = payload.clone();\n                        async move {\n                            client\n                                .send_text(payload.expose_secret().to_owned(), None)\n                                .await\n                                .map_err(|e| {\n                                    BitmexWsError::ClientError(format!(\"Send failed: {e}\"))\n                                })\n                        }\n                    },\n                    should_retry_bitmex_error,\n                    |e| create_bitmex_timeout_error(e.to_string()),\n                )\n                .execute()\n                .await\n                .map_err(|e| anyhow::anyhow!(\"{e}\"))\n        } else {\n            Err(anyhow::anyhow!(\"No active WebSocket client\"))\n        }\n    }\n\n    pub(super) async fn next(&mut self) -> Option<BitmexWsMessage> {\n        loop {\n            tokio::select! {\n                Some(cmd) = self.cmd_rx.recv() => {\n                    match cmd {\n                        HandlerCommand::SetClient(client) => {\n                            log::debug!(\"WebSocketClient received by handler\");\n                            self.inner = Some(client);\n                        }\n                        HandlerCommand::Disconnect => {\n                            log::debug!(\"Disconnect command received\");\n\n                            if let Some(client) = self.inner.take() {\n                                client.disconnect().await;\n                            }","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/bitmex/src/websocket/handler.rs#L103-L139","documentation":"send_secret_with_retry in the BitMEX WebSocket handler attempts an authenticated send but no WebSocket client/connection is currently active, so there is nothing to send on. The guard prevents a panic/dereference of an absent connection.","triggerScenarios":"send_with_retry invoked (e.g. to (re)send the auth secret) after the WebSocket client was dropped, before connection was established, or after a disconnect closed the client slot.","commonSituations":"Calling a subscription/auth path before connect() completed; racing reconnect logic where the old client is cleared before the new one is installed; shutting down the adapter while an auth send is in flight.","solutions":["Ensure the WebSocket client is connected before triggering authenticated sends (await the connect future).","Re-create/reconnect the client and retry the send instead of propagating the failure.","Check reconnect handling: only call send_with_retry while a live client exists.","Review shutdown ordering so pending sends are cancelled before the client is dropped."],"exampleFix":"// before\nsend_secret_with_retry(&secret).await?;\n// after\nif client_is_active() {\n    send_secret_with_retry(&secret).await?;\n} else {\n    log::warn!(\"Skipping secret send: no active WebSocket client\");\n    reconnect_and_auth().await?;\n}","handlingStrategy":"retry","validationCode":"if !ws.is_connected() { ws.reconnect().await?; }","typeGuard":"fn active_client(ws: &BitmexWsHandle) -> Option<&BitmexWsClient> { ws.client() }","tryCatchPattern":"if let Err(e) = send_with_retry(&msg).await {\n    if e.to_string().contains(\"No active WebSocket client\") {\n        ws.reconnect().await?;\n        send_with_retry(&msg).await?;\n    } else { return Err(e); }\n}","preventionTips":["Always await connect() before any authenticated send.","Serialize sends through a single task so shutdown cannot race an auth send.","Re-authenticate automatically as part of the reconnect sequence."],"tags":["websocket","bitmex","connection","lifecycle"],"backgroundTag":"connection-refused","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"}