{"record":{"id":"15d72422a86e7b71","repo":"shadowsocks/shadowsocks-windows","slug":"proxy-request-failed","errorCode":null,"errorMessage":"Proxy request failed","messagePattern":"Proxy request failed","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"shadowsocks-csharp/Proxy/Socks5Proxy.cs","lineNumber":109,"sourceCode":"                request[4] = (byte)hostByteCount;\n                enc.GetBytes(dep.Host, 0, dep.Host.Length, request, 5);\n\n                port = dep.Port;\n            }\n            else\n            {\n                switch (DestEndPoint.AddressFamily)\n                {\n                    case AddressFamily.InterNetwork:\n                        request = new byte[4 + 4 + 2];\n                        atyp = 1; // IP V4 address\n                        break;\n                    case AddressFamily.InterNetworkV6:\n                        request = new byte[4 + 16 + 2];\n                        atyp = 4; // IP V6 address\n                        break;\n                    default:\n                        throw new Exception(I18N.GetString(\"Proxy request failed\"));\n                }\n                port = ((IPEndPoint) DestEndPoint).Port;\n                var addr = ((IPEndPoint)DestEndPoint).Address.GetAddressBytes();\n                Array.Copy(addr, 0, request, 4, request.Length - 4 - 2);\n            }\n\n            // 构造request包剩余部分\n            request[0] = 5;\n            request[1] = 1;\n            request[2] = 0;\n            request[3] = atyp;\n            request[request.Length - 2] = (byte) ((port >> 8) & 0xff);\n            request[request.Length - 1] = (byte) (port & 0xff);\n\n            var st = new Socks5State();\n            st.Callback = callback;\n            st.AsyncState = state;\n","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/shadowsocks/shadowsocks-windows/blob/891d971682eefcaa2e640258d3b352a3ad3b2233/shadowsocks-csharp/Proxy/Socks5Proxy.cs#L91-L127","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Resolve the destination to a DnsEndPoint, or an IPv4/IPv6 IPEndPoint before calling BeginConnectDest.","Filter out unsupported address families upstream and surface a clearer error to the user.","Ensure IPv6 is enabled in the runtime if IPv6 destinations are expected."],"exampleFix":"// before\nproxy.BeginConnectDest(destEndPoint, cb, state); // destEndPoint is Unknown family\n\n// after\nif (destEndPoint is IPEndPoint ip &&\n    ip.AddressFamily != AddressFamily.InterNetwork &&\n    ip.AddressFamily != AddressFamily.InterNetworkV6)\n    throw new ArgumentException(\"unsupported address family for SOCKS5\");\nproxy.BeginConnectDest(destEndPoint, cb, state);","handlingStrategy":"type-guard","validationCode":"static bool IsSocks5Supported(EndPoint ep) {\n    if (ep is DnsEndPoint) return true;\n    if (ep is IPEndPoint ip)\n        return ip.AddressFamily == AddressFamily.InterNetwork\n            || ip.AddressFamily == AddressFamily.InterNetworkV6;\n    return false;\n}\nif (!IsSocks5Supported(destEndPoint)) throw new ArgumentException(\"unsupported destination\");","typeGuard":"static bool CanRouteOverSocks5(EndPoint ep) =>\n    ep is DnsEndPoint ||\n    (ep is IPEndPoint ip &&\n        (ip.AddressFamily == AddressFamily.InterNetwork ||\n         ip.AddressFamily == AddressFamily.InterNetworkV6));","tryCatchPattern":"try { proxy.BeginConnectDest(destEndPoint, cb, state); }\ncatch (Exception ex) when (ex.Message.Contains(\"Proxy request failed\")) {\n    // unsupported destination — report to the user, do not blind-retry\n    logger.Warn(ex, \"unsupported SOCKS5 destination family\");\n}","preventionTips":["Resolve destinations to a DnsEndPoint or an IPv4/IPv6 IPEndPoint before SOCKS5 routing.","Reject unsupported address families early with a clear user-facing message."],"tags":["proxy","socks5","networking","address-family"],"backgroundTag":null,"analyzedSha":"891d971682eefcaa2e640258d3b352a3ad3b2233","analyzedAt":"2026-08-13T10:12:34.434Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}