microsoft/garnet · error · Exception

Failed to connect at {EndPoint}

Error message

Failed to connect at {EndPoint}

What it means

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.

Source

Thrown at libs/client/GarnetClient.cs:353

                        NoDelay = true
                    };

                    if (TryConnectSocket(socket, endpoint))
                        return socket;
                }
            }
            else
            {
                var socket = new Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Unspecified);
                if (EndPoint is not UnixDomainSocketEndPoint)
                    socket.NoDelay = true;

                if (TryConnectSocket(socket, EndPoint))
                    return socket;
            }

            logger?.LogWarning("Failed to connect at {endpoint}", EndPoint);
            throw new Exception($"Failed to connect at {EndPoint}");
        }

        /// <inheritdoc cref="ConnectSendSocket"/>
        private async Task<Socket> ConnectSendSocketAsync(int millisecondsTimeout = 0, CancellationToken cancellationToken = default)
        {
            if (EndPoint is DnsEndPoint dnsEndpoint)
            {
                var hostEntries = await Dns.GetHostEntryAsync(dnsEndpoint.Host, cancellationToken).ConfigureAwait(false);
                // Try all available DNS entries if a hostName is provided
                foreach (var addressEntry in hostEntries.AddressList)
                {
                    var endpoint = new IPEndPoint(addressEntry, dnsEndpoint.Port);
                    var socket = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
                    {
                        NoDelay = true
                    };

                    if (await TryConnectSocketAsync(socket, endpoint, millisecondsTimeout, cancellationToken).ConfigureAwait(false))

View on GitHub (pinned to 951b0fc683)

Solutions

  1. Confirm the Garnet server is up and listening on the configured endpoint.
  2. Validate the address/port and that the client host can route to it.
  3. For DnsEndPoint, ensure resolved addresses are reachable (watch IPv6-only records).
  4. Retry with backoff for transient failures during startup.

Example fix

// before
var client = new GarnetClient(endpoint);
client.Connect();

// after — wait for readiness and retry
var client = new GarnetClient(endpoint);
for (int i = 0; i < 5; i++)
    try { client.Connect(); break; }
    catch (Exception) when (i < 4) { await Task.Delay(500 << i); }
Defensive patterns

Strategy: retry

Validate before calling

// Preflight reachability for the lighter-weight GarnetClient
using var probe = new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
bool ok = probe.BeginConnect(endpoint, null, null).AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(2));

Type guard

if (endpoint is null) throw new ArgumentNullException(nameof(endpoint));

Try / catch

try { client.Connect(); }
catch (Exception ex) { logger?.LogError(ex, "GarnetClient connect failed"); /* retry/backoff */ }

Prevention

When it happens

Trigger: GarnetClient.Connect to an unreachable, down, or firewalled server; DNS resolves but no address accepts the TCP connection; Unix domain socket path invalid.

Common situations: Server not started; wrong address/port; firewall/security group; stale DNS; container networking mismatch; connecting before the server listener is ready.

Related errors


AI-assisted analysis of microsoft/garnet@951b0fc683 (2026-08-13). Data as JSON: /api/errors/ba457169222dace1. Report an issue: GitHub.