{"record":{"id":"def7e0c229d04efd","repo":"nautechsystems/nautilus_trader","slug":"failed-to-register-coinbase-websocket-consumption","errorCode":null,"errorMessage":"failed to register Coinbase WebSocket consumption task; startup rollback failed: {shutdown_error}","messagePattern":"failed to register Coinbase WebSocket consumption task; startup rollback failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/coinbase/src/data/mod.rs","lineNumber":298,"sourceCode":"                    }\n                    msg_opt = out_rx.recv() => {\n                        match msg_opt {\n                            Some(msg) => dispatch_ws_message(msg, &data_sender, &status_subs),\n                            None => {\n                                log::debug!(\"WebSocket output channel closed\");\n                                break;\n                            }\n                        }\n                    }\n                }\n            }\n\n            log::debug!(\"Coinbase WebSocket consumption loop finished\");\n        };\n\n        if let Err(e) = self.session_tasks.spawn(future) {\n            if let Err(shutdown_error) = self.ws_client.disconnect().await {\n                return Err(anyhow::Error::new(e).context(format!(\n                    \"failed to register Coinbase WebSocket consumption task; startup rollback \\\n                     failed: {shutdown_error}\"\n                )));\n            }\n            return Err(anyhow::Error::new(e)\n                .context(\"failed to register Coinbase WebSocket consumption task\"));\n        }\n        log::debug!(\"WebSocket consumption task registered\");\n        Ok(())\n    }\n\n    async fn teardown_partial_connect(&mut self) -> anyhow::Result<()> {\n        self.cancellation_token.cancel();\n        self.session_tasks.begin_shutdown();\n        self.command_tasks.begin_shutdown();\n        self.deriv_polls.shutdown();\n        self.ws_client.begin_shutdown();\n","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/coinbase/src/data/mod.rs#L280-L316","documentation":"This error is returned by spawn_ws when the Coinbase WebSocket consumption task cannot be registered with the session task spawner AND the rollback (ws_client.disconnect()) also fails. The original spawn error is preserved as the source, with the disconnect failure appended to the context, so the caller knows both the connection setup failed and the client may still be connected. It surfaces from connect().","triggerScenarios":"session_tasks.spawn(future) returns Err (e.g. the runtime/session task group is already closed or aborted), and the subsequent self.ws_client.disconnect().await also returns Err.","commonSituations":"Calling connect() after the live runner's task session was shut down; tokio runtime shutting down concurrently; ws_client in a broken state where disconnect itself errors (already-closed transport, poisoned state); bugs in task-group lifecycle management.","solutions":["Inspect the chained source error to distinguish the spawn failure from the disconnect failure","Ensure connect() is called before any session teardown — do not reuse a data client whose task session is closed","Manually force-disconnect/reset the ws_client to clear the possibly-still-open connection","Recreate the Coinbase data client instance rather than reconnecting a partially-initialized one","Check for runtime shutdown races (e.g. stopping the live node during connect)"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Only connect within a live session scope\nif session_is_closed() {\n    return Err(anyhow!(\"cannot connect Coinbase data client: session already closed\"));\n}","typeGuard":"fn is_rollback_failure(err: &anyhow::Error) -> bool {\n    err.to_string().contains(\"startup rollback failed\")\n}","tryCatchPattern":"match connect(client).await {\n    Err(e) if e.to_string().contains(\"startup rollback failed\") => {\n        // connection AND cleanup failed: force reset the client\n        client.force_disconnect()?;\n        Err(e)\n    }\n    other => other,\n}","preventionTips":["Never call connect() on a client whose task session was already shut down","Avoid stopping the live node concurrently with client startup","Recreate the client instance after a failed startup instead of reconnecting","Ensure the tokio runtime outlives all client connect/disconnect calls"],"tags":["websocket","coinbase","task-spawn","startup"],"backgroundTag":"websocket-connect-failed","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"}