{"record":{"id":"c9f24b0c71d7e476","repo":"XX-net/XX-Net","slug":"request-version-d-error-c9f24b","errorCode":null,"errorMessage":"request version:%d error","messagePattern":"request version:(.+?) error","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/x_tunnel/local/proxy_handler.py","lineNumber":239,"sourceCode":"\n        g.session.conn_list[conn_id].start(block=True)\n\n    def socks5_handler(self):\n        sock = self.connection\n        auth_mode_num = ord(self.read_bytes(1))\n        data = self.read_bytes(auth_mode_num)\n\n        sock.send(b\"\\x05\\x00\")  # socks version 5, no auth needed.\n        try:\n            data = self.read_bytes(4)\n        except Exception as e:\n            xlog.debug(\"socks5 auth num:%d, list:%s\", auth_mode_num, utils.str2hex(data))\n            xlog.warn(\"socks5 protocol error:%r\", e)\n            return\n\n        socks_version = ord(data[0:1])\n        if socks_version != 5:\n            xlog.warn(\"request version:%d error\", socks_version)\n            return\n\n        command = ord(data[1:2])\n        if command != 1:  # 1. Tcp connect\n            xlog.warn(\"request not supported command mode:%d\", command)\n            sock.send(b\"\\x05\\x07\\x00\\x01\")  # Command not supported\n            return\n\n        addrtype_pack = data[3:4]\n        addrtype = ord(addrtype_pack)\n        if addrtype == 1:  # IPv4\n            addr_pack = self.read_bytes(4)\n            addr = socket.inet_ntoa(addr_pack)\n        elif addrtype == 3:  # Domain name\n            domain_len_pack = self.read_bytes(1)[0:1]\n            domain_len = ord(domain_len_pack)\n            domain = self.read_bytes(domain_len)\n            addr_pack = domain_len_pack + domain","sourceCodeStart":221,"sourceCodeEnd":257,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/proxy_handler.py#L221-L257","documentation":"Logged by X-Tunnel's socks5_handler when the request frame's version byte is not 5 (e.g. 4 for SOCKS4). The handler refuses the request and closes the connection. Note the preceding debug line referencing auth_mode_num/data is leftover from the greeting stage and will itself often fail with NameError on that path in strict review — the effective signal is the non-5 version.","triggerScenarios":"A SOCKS4 client or a non-SOCKS protocol sends bytes to the X-Tunnel local SOCKS5 port after the initial greeting exchange.","commonSituations":"Client proxy configured as SOCKS4 instead of SOCKS5, wrong port targeted by another application, protocol garbage from port scans.","solutions":["Set the client to SOCKS5: socks5://127.0.0.1:<port>","Confirm the application is connecting to the X-Tunnel local port, not another service","Remove the stale debug line referencing undefined auth_mode_num/data in the except block to avoid masking the real error"],"exampleFix":"# before\nexcept Exception as e:\n    xlog.debug(\"socks5 auth num:%d, list:%s\", auth_mode_num, utils.str2hex(data))\n    xlog.warn(\"socks5 protocol error:%r\", e)\n\n# after\nexcept Exception as e:\n    xlog.warn(\"socks5 protocol error:%r\", e)","handlingStrategy":"validation","validationCode":"# client side\nassert proxy_scheme == 'socks5', 'X-Tunnel local proxy is SOCKS5 only'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use socks5:// in client configuration","Remove the stale debug line in the except block so real errors surface"],"tags":["socks5","protocol-mismatch","proxy"],"backgroundTag":"socks-protocol-version-mismatch","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}