{"record":{"id":"ba457169222dace1","repo":"microsoft/garnet","slug":"failed-to-connect-at-endpoint-ba4571","errorCode":null,"errorMessage":"Failed to connect at {EndPoint}","messagePattern":"Failed to connect at (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/client/GarnetClient.cs","lineNumber":353,"sourceCode":"                        NoDelay = true\n                    };\n\n                    if (TryConnectSocket(socket, endpoint))\n                        return socket;\n                }\n            }\n            else\n            {\n                var socket = new Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Unspecified);\n                if (EndPoint is not UnixDomainSocketEndPoint)\n                    socket.NoDelay = true;\n\n                if (TryConnectSocket(socket, EndPoint))\n                    return socket;\n            }\n\n            logger?.LogWarning(\"Failed to connect at {endpoint}\", EndPoint);\n            throw new Exception($\"Failed to connect at {EndPoint}\");\n        }\n\n        /// <inheritdoc cref=\"ConnectSendSocket\"/>\n        private async Task<Socket> ConnectSendSocketAsync(int millisecondsTimeout = 0, CancellationToken cancellationToken = default)\n        {\n            if (EndPoint is DnsEndPoint dnsEndpoint)\n            {\n                var hostEntries = await Dns.GetHostEntryAsync(dnsEndpoint.Host, cancellationToken).ConfigureAwait(false);\n                // Try all available DNS entries if a hostName is provided\n                foreach (var addressEntry in hostEntries.AddressList)\n                {\n                    var endpoint = new IPEndPoint(addressEntry, dnsEndpoint.Port);\n                    var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)\n                    {\n                        NoDelay = true\n                    };\n\n                    if (await TryConnectSocketAsync(socket, endpoint, millisecondsTimeout, cancellationToken).ConfigureAwait(false))","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/client/GarnetClient.cs#L335-L371","documentation":"ConnectSendSocket (sync) in GarnetClient (the lightweight client) is the mirror of the GarnetClientSession version: after iterating all DNS-resolved addresses (for DnsEndPoint) or the single EndPoint (IPEndPoint/UnixDomainSocketEndPoint) via TryConnectSocket, it logs a warning and throws 'Failed to connect at {EndPoint}'. The same root causes apply; this is the lighter-weight client's terminal connect-failure path.","triggerScenarios":"GarnetClient.Connect to an unreachable, down, or firewalled server; DNS resolves but no address accepts the TCP connection; Unix domain socket path invalid.","commonSituations":"Server not started; wrong address/port; firewall/security group; stale DNS; container networking mismatch; connecting before the server listener is ready.","solutions":["Confirm the Garnet server is up and listening on the configured endpoint.","Validate the address/port and that the client host can route to it.","For DnsEndPoint, ensure resolved addresses are reachable (watch IPv6-only records).","Retry with backoff for transient failures during startup."],"exampleFix":"// before\nvar client = new GarnetClient(endpoint);\nclient.Connect();\n\n// after — wait for readiness and retry\nvar client = new GarnetClient(endpoint);\nfor (int i = 0; i < 5; i++)\n    try { client.Connect(); break; }\n    catch (Exception) when (i < 4) { await Task.Delay(500 << i); }","handlingStrategy":"retry","validationCode":"// Preflight reachability for the lighter-weight GarnetClient\nusing var probe = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);\nbool ok = probe.BeginConnect(endpoint, null, null).AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(2));","typeGuard":"if (endpoint is null) throw new ArgumentNullException(nameof(endpoint));","tryCatchPattern":"try { client.Connect(); }\ncatch (Exception ex) { logger?.LogError(ex, \"GarnetClient connect failed\"); /* retry/backoff */ }","preventionTips":["Ensure the server is up before client startup.","Validate address/port and routing.","Retry transient failures with backoff."],"tags":["csharp","network","connection","socket","garnet-client"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}