{"record":{"id":"f3b88ff2ad5224dd","repo":"microsoft/garnet","slug":"failed-to-connect-at-endpoint-f3b88f","errorCode":null,"errorMessage":"Failed to connect at {endpoint}","messagePattern":"Failed to connect at (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"libs/common/LightClient.cs","lineNumber":161,"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(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, cancellationToken).ConfigureAwait(false))","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/common/LightClient.cs#L143-L179","documentation":"Thrown by LightClient.ConnectSendSocket when no socket connection to the target endpoint can be established. It is the terminal failure after all connection attempts (DNS-resolved addresses or a direct endpoint) have been tried and none succeeded.","triggerScenarios":"All TCP/Unix-domain socket connect attempts to endpoint fail: connection refused, host unreachable, DNS resolves but no port listening, or timeout in TryConnectSocket.","commonSituations":"Target node down or not started; wrong host/port in config; firewall/network partition; Unix-domain socket path missing or wrong; peer overloaded and refusing connections.","solutions":["Verify the target endpoint is reachable and the server is listening (e.g. telnet/netcat to host:port).","Check the configured host/port or Unix socket path for typos.","Inspect network/firewall rules between client and target, then retry with backoff.","For DNS endpoints, confirm resolution returns live addresses."],"exampleFix":"// before\nvar socket = LightClient.ConnectSendSocket(endpoint);\n// after\nif (!LightClient.CanConnect(endpoint, timeout: TimeSpan.FromSeconds(2)))\n    throw new InvalidOperationException($\"Target not reachable: {endpoint}\");\nvar socket = LightClient.ConnectSendSocket(endpoint);","handlingStrategy":"retry","validationCode":"// Probe reachability before attempting the blocking connect\nusing var probe = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Unspecified);\nvar connected = probe.BeginConnect(endpoint, null, null);\nif (!connected.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(2)) || !probe.Connected)\n    throw new InvalidOperationException($\"Target not reachable: {endpoint}\");","typeGuard":null,"tryCatchPattern":"for (int attempt = 0; attempt < maxAttempts; attempt++)\n{\n    try { return LightClient.ConnectSendSocket(endpoint); }\n    catch (Exception ex) when (ex.Message.StartsWith(\"Failed to connect at\"))\n    {\n        logger?.LogWarning(\"Connect attempt {n}/{max} to {endpoint} failed: {msg}\", attempt + 1, maxAttempts, endpoint, ex.Message);\n        if (attempt == maxAttempts - 1) throw;\n        await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt)), ct);\n    }\n}\nthrow new Exception(\"unreachable\");","preventionTips":["Confirm the target endpoint is up and listening before connecting.","Wrap connect calls in exponential-backoff retry for transient failures.","Validate host/port or Unix socket path configuration at startup.","Check firewall/DNS rules between client and target."],"tags":["network","connection","client","garnet"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}