{"record":{"id":"69c50a3c10c0e317","repo":"nautechsystems/nautilus_trader","slug":"failed-to-terminate-coinbase-session-tasks-e","errorCode":null,"errorMessage":"Failed to terminate Coinbase session tasks: {e}","messagePattern":"Failed to terminate Coinbase session tasks: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/coinbase/src/execution.rs","lineNumber":264,"sourceCode":"        self.session_tasks.begin_shutdown();\n        self.ws_user.begin_shutdown();\n    }\n\n    async fn await_pending_tasks(&self) -> anyhow::Result<()> {\n        self.pending_tasks.begin_shutdown();\n        self.pending_tasks\n            .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to terminate Coinbase execution tasks: {e}\"))?;\n        Ok(())\n    }\n\n    async fn await_session_tasks(&self) -> anyhow::Result<()> {\n        self.session_tasks.begin_shutdown();\n        self.session_tasks\n            .finish_shutdown(Duration::from_secs(1), Duration::from_secs(2))\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to terminate Coinbase session tasks: {e}\"))?;\n        Ok(())\n    }\n\n    async fn teardown_partial_connect(&mut self) -> anyhow::Result<()> {\n        self.abort_session_tasks();\n        self.abort_pending_tasks();\n\n        if let Err(e) = self.ws_user.disconnect().await {\n            self.shutdown_errors.push(e.to_string());\n        }\n        let (session_result, pending_result) =\n            tokio::join!(self.await_session_tasks(), self.await_pending_tasks());\n        self.core.set_disconnected();\n\n        if let Err(e) = session_result {\n            self.shutdown_errors.push(e.to_string());\n        }\n","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/coinbase/src/execution.rs#L246-L282","documentation":"`await_session_tasks` shuts down the execution client's session-task set (WebSocket user-data session tasks) with the same 1s drain / 2s timeout, invoked from connect. Any failure from finish_shutdown is wrapped in this error.","triggerScenarios":"connect() called while the prior WebSocket user-data session tasks are still terminating and one hangs or panics beyond the 2-second timeout.","commonSituations":"Reconnecting after a WebSocket drop while the old session task is blocked reading a dead socket; runtime under load preventing graceful task completion.","solutions":["Wait and retry connect so the old session fully tears down","Check logs for the hung session task / WebSocket read stall","Confirm the WebSocket endpoint is reachable","Recreate the client if session task state is wedged","Increase the shutdown timeout if hangs are environmental"],"exampleFix":"// before\nloop { client.connect().await?; } // hot reconnect loop\n// after\nloop {\n    client.connect().await?;\n    tokio::time::sleep(Duration::from_secs(1)).await; // allow teardown\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"Failed to terminate Coinbase session tasks\") => {\n        tokio::time::sleep(Duration::from_secs(2)).await;\n        client.connect().await?; // retry once after teardown settles\n    }\n    other => other?,\n}","preventionTips":["Detect dead WebSocket connections quickly with heartbeats","Avoid reconnect storms; use capped backoff","Ensure the runtime is not starved (block_in_place misuse) so tasks can finish"],"tags":["rust","async","websocket","tasks","shutdown"],"backgroundTag":"request-timeout","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"}