{"record":{"id":"3f871ac37e3752d5","repo":"XX-net/XX-Net","slug":"socks5-r-connect-to-s-d-conn-id-d-closed-r","errorCode":null,"errorMessage":"socks5 %r connect to %s:%d conn_id:%d closed:%r","messagePattern":"socks5 %r connect to (.+?):(.+?) conn_id:(.+?) closed:%r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/x_tunnel/local/proxy_handler.py","lineNumber":283,"sourceCode":"            return\n\n        port = struct.unpack('>H', self.rfile.read(2))[0]\n\n        conn_id = proxy_session.create_conn(sock, addr, port)\n        if not conn_id:\n            xlog.warn(\"socks5 create conn to %s:%d fail\", addr, port)\n            reply = b\"\\x05\\x01\\x00\" + addrtype_pack + addr_pack + struct.pack(\">H\", port)\n            sock.send(reply)\n            return\n\n        xlog.info(\"socks5 %r connect to %s:%d conn:%d\", self.client_address, addr, port, conn_id)\n        reply = b\"\\x05\\x00\\x00\" + addrtype_pack + addr_pack + struct.pack(\">H\", port)\n        try:\n            sock.send(reply)\n        except Exception as e:\n            if conn_id in g.session.conn_list:\n                g.session.conn_list[conn_id].do_stop(\"close_on_Socks5_reply\")\n            xlog.warn(\"socks5 %r connect to %s:%d conn_id:%d closed:%r\", self.client_address, addr, port, conn_id, e)\n            return\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 https_handler(self):\n        line = self.read_crlf_line()\n        line = line.decode('iso-8859-1')\n        words = line.split()\n        if len(words) == 3:\n            command, path, version = words\n        elif len(words) == 2:\n            command, path = words\n            version = b\"HTTP/1.1\"\n        else:\n            xlog.warn(\"https req line fail:%s\", line)","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/proxy_handler.py#L265-L301","documentation":"After a successful SOCKS5 CONNECT and create_conn, sending the success reply to the client raised (client vanished/reset). The tunnel conn is stopped via do_stop and the warning logged with the exception.","triggerScenarios":"Client disconnects or RSTs between CONNECT request and reply; e.g. timeout or cancel in the client app.","commonSituations":"Apps with short connect timeouts, page navigations cancelling requests, mobile network switches.","solutions":["Usually benign — the tunnel is cleaned up automatically","Increase client connect timeout if frequent","Check client-side network stability"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    sock.send(reply)\nexcept Exception as e:\n    g.session.conn_list[conn_id].do_stop('client_gone')","preventionTips":["Raise client connect timeouts slightly"],"tags":["x-tunnel","socks5","client-disconnect"],"backgroundTag":"client-closed-connection","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}