{"record":{"id":"93fa27a0c5e2b9b8","repo":"ginuerzh/gost","slug":"socks5-udp-relay-failure","errorCode":null,"errorMessage":"SOCKS5 udp relay failure","messagePattern":"SOCKS5 udp relay failure","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"socks.go","lineNumber":615,"sourceCode":"\t\treturn nil, err\n\t}\n\n\tif Debug {\n\t\tlog.Log(\"[socks5] udp\\n\", req)\n\t}\n\n\treply, err := gosocks5.ReadReply(conn)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tif Debug {\n\t\tlog.Log(\"[socks5] udp\\n\", reply)\n\t}\n\n\tif reply.Rep != gosocks5.Succeeded {\n\t\tlog.Logf(\"[socks5] udp relay failure\")\n\t\treturn nil, fmt.Errorf(\"SOCKS5 udp relay failure\")\n\t}\n\tbaddr, err := net.ResolveUDPAddr(\"udp\", reply.Addr.String())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tlog.Logf(\"[socks5] udp associate on %s OK\", baddr)\n\n\tuc, err := net.DialUDP(\"udp\", nil, baddr)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t// log.Logf(\"udp laddr:%s, raddr:%s\", uc.LocalAddr(), uc.RemoteAddr())\n\n\treturn &socks5UDPConn{UDPConn: uc, taddr: taddr}, nil\n}\n\ntype socks5UDPTunConnector struct {\n\tUser *url.Userinfo","sourceCodeStart":597,"sourceCodeEnd":633,"githubUrl":"https://github.com/ginuerzh/gost/blob/a33fdbf4c98034f4bfeeaea9868909822b9c526d/socks.go#L597-L633","documentation":"The SOCKS5 UDP ASSOCIATE request was rejected by the proxy: gosocks5.ReadReply returned a reply whose Rep is not Succeeded. The library converts the server's refusal into this error instead of a UDP relay connection.","triggerScenarios":"socks5UDPConnector.ConnectContext with a udp-family network sends the SOCKS5 UDP ASSOCIATE request; the server answers with a failure reply (UDP relay not allowed, client address mismatch, server lacks UDP support).","commonSituations":"Proxy server has UDP relay disabled (common on hardened or commercial proxies); client's source IP differs from the address declared in the associate request (proxy rejects); firewall blocks the UDP relay port range.","solutions":["Enable UDP relay on the proxy server (e.g. allow udp in its config) or pick a proxy that supports UDP ASSOCIATE.","Ensure the TCP control connection originates from the same address the proxy expects for the UDP relay.","Check firewall rules allow the UDP ports the proxy replies with.","Fall back to TCP-based connectors (socks5/tls) if UDP relay is not required."],"exampleFix":"// before\nc := socks5UDPConnector{} // server: udp-relay disabled -> \"SOCKS5 udp relay failure\"\n// after\nserverCfg := \"udp-relay: true\" // enable on proxy, or use Socks5Connector() over TCP","handlingStrategy":"try-catch","validationCode":"// Ensure the control conn is TCP-capable before UDP ASSOCIATE\nif _, ok := ctrlConn.(*net.TCPConn); !ok {\n\treturn errors.New(\"udp associate requires a TCP control connection\")\n}","typeGuard":null,"tryCatchPattern":"relay, err := udpConnector.ConnectContext(ctx, ctrlConn, \"udp\", addr)\nif err != nil {\n\tif strings.Contains(err.Error(), \"udp relay failure\") {\n\t\t// proxy refused ASSOCIATE: check server udp-relay config, fall back to TCP\n\t\treturn tcpFallback(ctx, addr)\n\t}\n\treturn err\n}","preventionTips":["Enable UDP relay on the proxy server config.","Ensure the client IP matches the ASSOCIATE-declared address (no double NAT surprises).","Open firewall ports for the proxy's UDP relay range.","Probe UDP support once at startup and cache the capability."],"tags":["socks5","udp-relay","udp-associate","proxy-refused"],"backgroundTag":"socks-command-refused","analyzedSha":"a33fdbf4c98034f4bfeeaea9868909822b9c526d","analyzedAt":"2026-09-02T22:15:54.506Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}