{"record":{"id":"cd106a4d2503f08c","repo":"nautechsystems/nautilus_trader","slug":"ws-setup-error-channel-closed","errorCode":null,"errorMessage":"WS setup error channel closed","messagePattern":"WS setup error channel closed","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/binance/src/spot/execution.rs","lineNumber":2201,"sourceCode":") {\n    for report in reports {\n        normalize_spot_order_status_report(report, treat_expired_as_canceled);\n    }\n}\n\nasync fn wait_for_ws_setup_response(\n    timeout: Duration,\n    success: impl Future<Output = ()>,\n    setup_errors: &mut tokio::sync::mpsc::UnboundedReceiver<String>,\n    timeout_message: &'static str,\n) -> anyhow::Result<()> {\n    tokio::pin!(success);\n\n    let result = tokio::time::timeout(timeout, async {\n        tokio::select! {\n            () = &mut success => Ok(()),\n            err = setup_errors.recv() => {\n                anyhow::bail!(\n                    \"{}\",\n                    err.unwrap_or_else(|| \"WS setup error channel closed\".to_string()),\n                )\n            }\n        }\n    })\n    .await;\n\n    result.map_err(|_| anyhow::anyhow!(timeout_message))?\n}\n\n#[expect(clippy::too_many_arguments)]\nfn dispatch_ws_trading_message(\n    msg: BinanceSpotWsTradingMessage,\n    emitter: &ExecutionEventEmitter,\n    http_client: &BinanceSpotHttpClient,\n    account_id: AccountId,\n    treat_expired_as_canceled: bool,","sourceCodeStart":2183,"sourceCodeEnd":2219,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/binance/src/spot/execution.rs#L2183-L2219","documentation":"Raised inside `wait_for_ws_setup_response` when the setup-error channel closes without delivering an error message (`recv()` returned None). It indicates the WS setup supervision tasks shut down before either signalling success or an error — an unexpected lifecycle state during connection establishment.","triggerScenarios":"During `connect`, while waiting (with timeout) for the WS API session setup (session logon / subscription) to succeed, the `setup_errors` mpsc channel is dropped by its sender before an error message is sent — e.g. the setup task was aborted or completed without sending.","commonSituations":"Connect racing with a shutdown; a bug or early task termination in the WS setup pipeline; process shutting down while connect is still in flight.","solutions":["Retry the connect — the channel closure is usually a race with shutdown rather than a protocol error","Check whether connect was invoked concurrently with disconnect/teardown and serialize the calls","Enable debug logging around WS setup tasks to see why the sender dropped","If reproducible, inspect the setup task lifecycle for early termination (task abort/panic)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match connect().await {\n    Err(e) if e.to_string().contains(\"WS setup error channel closed\") => {\n        tokio::time::sleep(backoff).await;\n        // retry connect once\n    }\n    Err(e) => log::error!(\"connect failed: {e}\"),\n    Ok(()) => {},\n}","preventionTips":["Serialize connect/disconnect calls","Avoid shutting the node down while connect is pending","Add backoff-based reconnect logic","Capture debug logs of WS setup task lifecycle"],"tags":["binance","spot","websocket","connection-setup","channel-closed"],"backgroundTag":"connection-refused","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"}