{"record":{"id":"757baaaca9226152","repo":"microsoft/aspire","slug":"failed-to-connect-to-rpc-server-at-socketpath","errorCode":null,"errorMessage":"Failed to connect to RPC server at {socketPath}","messagePattern":"Failed to connect to RPC server at (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Projects/AppHostRpcClient.cs","lineNumber":213,"sourceCode":"            {\n                while ((DateTimeOffset.UtcNow - startTime) < TimeSpan.FromSeconds(ConnectionTimeoutSeconds))\n                {\n                    try\n                    {\n                        await pipeClient.ConnectAsync(cancellationToken).ConfigureAwait(false);\n                        return pipeClient;\n                    }\n                    catch (TimeoutException)\n                    {\n                        await Task.Delay(100, cancellationToken).ConfigureAwait(false);\n                    }\n                    catch (IOException)\n                    {\n                        await Task.Delay(100, cancellationToken).ConfigureAwait(false);\n                    }\n                }\n\n                throw new InvalidOperationException($\"Failed to connect to RPC server at {socketPath}\");\n            }\n            catch\n            {\n                pipeClient.Dispose();\n                throw;\n            }\n        }\n        else\n        {\n            var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);\n            try\n            {\n                var endpoint = new UnixDomainSocketEndPoint(socketPath);\n\n                while ((DateTimeOffset.UtcNow - startTime) < TimeSpan.FromSeconds(ConnectionTimeoutSeconds))\n                {\n                    try\n                    {","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Projects/AppHostRpcClient.cs#L195-L231","documentation":"Thrown by AppHostRpcClient.ConnectToServerAsync when connecting over a NamedPipeStream repeatedly throws IOException (the pipe endpoint isn't accepting connections) until retry attempts are exhausted. The CLI gives up waiting for the pipe-based RPC server to become reachable and reports the socket path it was trying.","triggerScenarios":"Calling ConnectToServerAsync (via stream) when every NamedPipeClientStream connect attempt throws IOException within the retry window, e.g. the server never created/accepted the pipe.","commonSituations":"AppHost server process crashed at startup, server is still starting and slower than the retry budget, pipe name mismatch, or running in a sandbox/container where named pipes are unavailable.","solutions":["Check the AppHost server process is running and inspect its logs for startup failure","Increase the retry/timeout budget if the server starts slowly","Restart the session to get a fresh socket path","Verify named pipes are functional in your environment (containers, Windows services)"],"exampleFix":"// before\nvar client = await AppHostRpcClient.ConnectToServerAsync(pipePath); // throws if server slow to start\n// after\nawait WaitForServerReadyAsync(pipePath, timeout: TimeSpan.FromSeconds(30));\nvar client = await AppHostRpcClient.ConnectToServerAsync(pipePath);","handlingStrategy":"retry","validationCode":"// Ensure the server is listening before connecting\nif (!WaitForPipeAvailability(pipePath, TimeSpan.FromSeconds(30)))\n    throw new TimeoutException($\"RPC server pipe {pipePath} not ready.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var client = await AppHostRpcClient.ConnectToServerAsync(pipePath, ct);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Failed to connect\"))\n{\n    logger.LogError(\"RPC server at {Path} unreachable; is the AppHost running?\", pipePath);\n}","preventionTips":["Wait for the server's readiness signal before connecting","Log server stdout/stderr to diagnose startup crashes","Verify named pipe support in sandboxed/containerized environments","Use a generous connect timeout for slow machines"],"tags":["rpc","named-pipes","ipc","connection"],"backgroundTag":"connection-refused","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}