{"record":{"id":"21a2da4aaa318c65","repo":"github/copilot-sdk","slug":"runtime-shutdown-timed-out-during-client-stop","errorCode":null,"errorMessage":"runtime.shutdown timed out during Client::stop","messagePattern":"runtime\\.shutdown timed out during Client::stop","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"rust/src/lib.rs","lineNumber":2873,"sourceCode":"            match tokio::time::timeout(RUNTIME_SHUTDOWN_TIMEOUT, self.rpc().runtime().shutdown())\n                .await\n            {\n                Ok(Ok(())) => {\n                    debug!(\n                        elapsed_ms = runtime_shutdown_start.elapsed().as_millis(),\n                        \"Client::stop runtime shutdown complete\"\n                    );\n                }\n                Ok(Err(e)) => {\n                    warn!(\n                        elapsed_ms = runtime_shutdown_start.elapsed().as_millis(),\n                        error = %e,\n                        \"runtime.shutdown failed during Client::stop\",\n                    );\n                    errors.push(e);\n                }\n                Err(_) => {\n                    let e = std::io::Error::new(\n                        std::io::ErrorKind::TimedOut,\n                        \"runtime.shutdown timed out during Client::stop\",\n                    );\n                    warn!(\n                        elapsed_ms = runtime_shutdown_start.elapsed().as_millis(),\n                        timeout = ?RUNTIME_SHUTDOWN_TIMEOUT,\n                        error = %e,\n                        \"runtime.shutdown timed out during Client::stop\",\n                    );\n                    errors.push(e.into());\n                }\n            }\n        }\n\n        let child = self.inner.child.lock().take();\n        let process_tree = self.inner.process_tree.lock().take();\n        *self.inner.state.lock() = ConnectionState::Disconnected;\n        *self.inner.models_cache.lock() = Arc::new(tokio::sync::OnceCell::new());","sourceCodeStart":2855,"sourceCodeEnd":2891,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/rust/src/lib.rs#L2855-L2891","documentation":"During Client::stop, the code awaits runtime.shutdown() with a bounded timeout (RUNTIME_SHUTDOWN_TIMEOUT). If the async runtime does not finish shutting down in time, the library raises TimedOut and records it among shutdown errors rather than hanging forever.","triggerScenarios":"Calling Client::stop while background tasks (writer actor, pending RPC handlers, leaked subscriptions) block runtime shutdown past the timeout, or awaiting shutdown from within a task on the same runtime.","commonSituations":"Calling stop from inside code running on the client's own runtime; open streams/handlers keeping tasks alive; a hung transport read preventing task completion; slow test teardown.","solutions":["Call Client::stop from outside the client's runtime (or a separate thread/runtime) to avoid self-deadlock","Cancel/drop active streams, subscriptions, and pending requests before stop","Increase or make configurable the shutdown timeout if teardown is legitimately slow","Log the pushed shutdown errors to find which task refused to finish"],"exampleFix":"// before\nclient.stop().await?; // called from a task on client's runtime -> timeout\n// after\nlet handle = tokio::spawn(async move { client.stop().await });\nlet _ = tokio::time::timeout(Duration::from_secs(10), handle).await;","handlingStrategy":"try-catch","validationCode":"// Rust: call stop from outside the client's runtime\nlet not_inside_runtime = std::thread::current().name().is_none(); // or spawn stop on a dedicated thread","typeGuard":null,"tryCatchPattern":"// Rust\nif let Err(e) = client.stop().await {\n    tracing::warn!(\"stop incomplete: {e}; dropping client anyway\");\n}","preventionTips":["Never call Client::stop from within the client's own runtime tasks","Close streams/subscriptions before stopping","Treat stop timeouts as non-fatal teardown warnings and log pushed errors"],"tags":["rust","async","shutdown","timeout"],"backgroundTag":"request-timeout","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}