{"record":{"id":"c46e67dcd177134b","repo":"XX-net/XX-Net","slug":"socks5-protocol-error-r","errorCode":null,"errorMessage":"socks5 protocol error:%r","messagePattern":"socks5 protocol error:%r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/x_tunnel/local/proxy_handler.py","lineNumber":234,"sourceCode":"        reply = b\"\\x00\\x5a\" + addr_pack + struct.pack(\">H\", port)\n        sock.send(reply)\n\n        if len(self.read_buffer) - self.buffer_start:\n            g.session.conn_list[conn_id].transfer_received_data(self.read_buffer[self.buffer_start:])\n\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)","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/proxy_handler.py#L216-L252","documentation":"The X-Tunnel socks5_handler failed while reading the 4-byte SOCKS5 request header (read_bytes(4) threw). The exception is logged as a protocol error and the handler returns, dropping the connection. Typical cause: client disconnected after the greeting, or sent fewer bytes than required.","triggerScenarios":"Client sends SOCKS5 greeting, receives the no-auth reply, then closes or stalls before sending the 4-byte request — read_bytes times out or raises EOF.","commonSituations":"Probers that only complete half a handshake, real clients behind unstable connections, timeouts from read_bytes being shorter than slow clients need.","solutions":["Usually benign; increase the read timeout if slow clients are being cut off","Verify clients complete the full SOCKS5 handshake (version, command, addr-type, address)","Ignore/log-filter if caused by scanners probing the port"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    data = self.read_bytes(4)\nexcept Exception as e:\n    xlog.warn('socks5 protocol error:%r', e)\n    return","preventionTips":["Increase read timeout for slow clients","Verify clients complete the full SOCKS5 request after the greeting"],"tags":["socks5","protocol-error","incomplete-handshake"],"backgroundTag":"incomplete-protocol-handshake","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}