shadowsocks/shadowsocks-windows · error · Exception

Proxy request failed

Error message

Proxy request failed

What it means

Exception thrown by Socks5Proxy.BeginConnectDest when the destination endpoint's AddressFamily is neither InterNetwork (IPv4) nor InterNetworkV6 (IPv6). The SOCKS5 request builder only knows how to serialise IPv4 (atyp=1) and IPv6 (atyp=4) IPEndPoints (DnsEndPoint is handled separately above), so any other family is rejected before a malformed request packet could be sent.

Source

Thrown at shadowsocks-csharp/Proxy/Socks5Proxy.cs:109

                request[4] = (byte)hostByteCount;
                enc.GetBytes(dep.Host, 0, dep.Host.Length, request, 5);

                port = dep.Port;
            }
            else
            {
                switch (DestEndPoint.AddressFamily)
                {
                    case AddressFamily.InterNetwork:
                        request = new byte[4 + 4 + 2];
                        atyp = 1; // IP V4 address
                        break;
                    case AddressFamily.InterNetworkV6:
                        request = new byte[4 + 16 + 2];
                        atyp = 4; // IP V6 address
                        break;
                    default:
                        throw new Exception(I18N.GetString("Proxy request failed"));
                }
                port = ((IPEndPoint) DestEndPoint).Port;
                var addr = ((IPEndPoint)DestEndPoint).Address.GetAddressBytes();
                Array.Copy(addr, 0, request, 4, request.Length - 4 - 2);
            }

            // 构造request包剩余部分
            request[0] = 5;
            request[1] = 1;
            request[2] = 0;
            request[3] = atyp;
            request[request.Length - 2] = (byte) ((port >> 8) & 0xff);
            request[request.Length - 1] = (byte) (port & 0xff);

            var st = new Socks5State();
            st.Callback = callback;
            st.AsyncState = state;

View on GitHub (pinned to 891d971682)

Solutions

  1. Resolve the destination to a DnsEndPoint, or an IPv4/IPv6 IPEndPoint before calling BeginConnectDest.
  2. Filter out unsupported address families upstream and surface a clearer error to the user.
  3. Ensure IPv6 is enabled in the runtime if IPv6 destinations are expected.

Example fix

// before
proxy.BeginConnectDest(destEndPoint, cb, state); // destEndPoint is Unknown family

// after
if (destEndPoint is IPEndPoint ip &&
    ip.AddressFamily != AddressFamily.InterNetwork &&
    ip.AddressFamily != AddressFamily.InterNetworkV6)
    throw new ArgumentException("unsupported address family for SOCKS5");
proxy.BeginConnectDest(destEndPoint, cb, state);
Defensive patterns

Strategy: type-guard

Validate before calling

static bool IsSocks5Supported(EndPoint ep) {
    if (ep is DnsEndPoint) return true;
    if (ep is IPEndPoint ip)
        return ip.AddressFamily == AddressFamily.InterNetwork
            || ip.AddressFamily == AddressFamily.InterNetworkV6;
    return false;
}
if (!IsSocks5Supported(destEndPoint)) throw new ArgumentException("unsupported destination");

Type guard

static bool CanRouteOverSocks5(EndPoint ep) =>
    ep is DnsEndPoint ||
    (ep is IPEndPoint ip &&
        (ip.AddressFamily == AddressFamily.InterNetwork ||
         ip.AddressFamily == AddressFamily.InterNetworkV6));

Try / catch

try { proxy.BeginConnectDest(destEndPoint, cb, state); }
catch (Exception ex) when (ex.Message.Contains("Proxy request failed")) {
    // unsupported destination — report to the user, do not blind-retry
    logger.Warn(ex, "unsupported SOCKS5 destination family");
}

Prevention

When it happens

Trigger: DestEndPoint is an IPEndPoint whose AddressFamily is not IPv4 or IPv6 (e.g. Unix domain, AppleTalk, Unknown). destEndPoint is neither a DnsEndPoint nor a supported IPEndPoint. The destination resolved to an address family the SOCKS5 layer cannot encode.

Common situations: A Unix-domain socket endpoint accidentally passed as the SOCKS5 destination. An IPv6-disabled host resolving to an unexpected family. Custom EndPoint subclasses passed through this path.

Related errors


AI-assisted analysis of shadowsocks/shadowsocks-windows@891d971682 (2026-08-13). Data as JSON: /api/errors/15d72422a86e7b71. Report an issue: GitHub.