nautechsystems/nautilus_trader · error
No active WebSocket client
Error message
No active WebSocket client
What it means
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.
Source
Thrown at crates/adapters/bitmex/src/websocket/handler.rs:121
|| {
let payload = payload.clone();
async move {
client
.send_text(payload.expose_secret().to_owned(), None)
.await
.map_err(|e| {
BitmexWsError::ClientError(format!("Send failed: {e}"))
})
}
},
should_retry_bitmex_error,
|e| create_bitmex_timeout_error(e.to_string()),
)
.execute()
.await
.map_err(|e| anyhow::anyhow!("{e}"))
} else {
Err(anyhow::anyhow!("No active WebSocket client"))
}
}
pub(super) async fn next(&mut self) -> Option<BitmexWsMessage> {
loop {
tokio::select! {
Some(cmd) = self.cmd_rx.recv() => {
match cmd {
HandlerCommand::SetClient(client) => {
log::debug!("WebSocketClient received by handler");
self.inner = Some(client);
}
HandlerCommand::Disconnect => {
log::debug!("Disconnect command received");
if let Some(client) = self.inner.take() {
client.disconnect().await;
}View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
send_secret_with_retry(&secret).await?;
// after
if client_is_active() {
send_secret_with_retry(&secret).await?;
} else {
log::warn!("Skipping secret send: no active WebSocket client");
reconnect_and_auth().await?;
} Defensive patterns
Strategy: retry
Validate before calling
if !ws.is_connected() { ws.reconnect().await?; } Type guard
fn active_client(ws: &BitmexWsHandle) -> Option<&BitmexWsClient> { ws.client() } Try / catch
if let Err(e) = send_with_retry(&msg).await {
if e.to_string().contains("No active WebSocket client") {
ws.reconnect().await?;
send_with_retry(&msg).await?;
} else { return Err(e); }
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: ECONNREFUSED and "connection refused" / "could not connect to server" errors: what they mean and how to fix them — this error's family across 44 libraries.
Related errors
- std::mem::take(&mut self.shutdown_errors).join("; ")
- WebSocket output receiver not available
- Failed to start Binance Spot session generation: {e}
- std::mem::take(&mut self.shutdown_errors).join("; ")
- Binance Spot public JSON stream pool is shutting down
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/39f4ef3d6878ff72.
Report an issue: GitHub.