{"record":{"id":"91be4bd11573aa8d","repo":"Hmbown/CodeWhale","slug":"mcp-sse-connect-cancelled-before-the-request-compl","errorCode":null,"errorMessage":"MCP SSE connect cancelled before the request completed","messagePattern":"MCP SSE connect cancelled before the request completed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/tui/src/mcp/sse.rs","lineNumber":111,"sourceCode":"        auth: McpHttpAuth,\n        tx: tokio::sync::mpsc::Sender<SseInbound>,\n        cancel_token: tokio_util::sync::CancellationToken,\n    ) -> Result<()> {\n        let headers = tokio::select! {\n            biased;\n            _ = cancel_token.cancelled() => {\n                anyhow::bail!(\"MCP SSE connect cancelled before authentication completed\")\n            }\n            headers = auth.resolved_headers() => headers?,\n        };\n        let request = apply_safe_custom_headers(\n            with_default_mcp_http_headers(client.get(&url), false),\n            &headers,\n        );\n        let response = tokio::select! {\n            biased;\n            _ = cancel_token.cancelled() => {\n                anyhow::bail!(\"MCP SSE connect cancelled before the request completed\")\n            }\n            response = request.send() => response.with_context(|| {\n                format!(\n                    \"MCP SSE connect failed (transport=http url={})\",\n                    mask_url_secrets(&url),\n                )\n            })?,\n        };\n        let status = response.status();\n        if !status.is_success() {\n            let body_excerpt = bounded_body_excerpt(response, ERROR_BODY_PREVIEW_BYTES).await;\n            let body_excerpt = auth.server_error_preview(&body_excerpt);\n            anyhow::bail!(\n                \"MCP SSE rejected (transport=http url={} status={}): {}\",\n                mask_url_secrets(&url),\n                status,\n                body_excerpt,\n            );","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/crates/tui/src/mcp/sse.rs#L93-L129","documentation":"The same cancellation race, but the token fired while the initial HTTP GET to the SSE URL was awaiting a response. The bail stops the connect future from continuing after the caller already abandoned this transport instance.","triggerScenarios":"CancellationToken cancelled while the GET to the SSE URL is in flight — the user aborted the connect attempt, the session is shutting down, or a supervisor restarted the MCP client mid-request.","commonSituations":"Slow MCP endpoints combined with quick shutdowns; flaky networks where the user cancels before the first response; automated test teardown cancelling freshly spawned transports.","solutions":["No action needed if it occurs during shutdown — this is the designed abort path","If it appears in steady-state logs, find the premature cancel() call site, usually a dropped or duplicated transport handle","Give connects a bounded budget or let them finish before cancelling to keep logs clean"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":"```rust\nfn is_request_cancelled(err: &anyhow::Error) -> bool {\n    format!(\"{err:#}\").contains(\"MCP SSE connect cancelled before the request completed\")\n}\n```","tryCatchPattern":"```rust\nmatch sse_transport.connect().await {\n    Err(e) if is_request_cancelled(&e) => return Ok(()), // caller gave up: don't retry\n    other => other?,\n}\n```","preventionTips":["Avoid spawning a transport and cancelling it in the same breath; sequence connect/teardown deliberately","Watch for duplicated transport handles causing premature cancel() calls"],"tags":["mcp","sse","cancellation","network"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}