{"record":{"id":"e1edc818d7384f1b","repo":"XX-net/XX-Net","slug":"do-unwrap-socks-connect-to-x-tunnel-for-s-d-prox","errorCode":null,"errorMessage":"do_unwrap_socks connect to x-tunnel for %s:%d proxy fail.","messagePattern":"do_unwrap_socks connect to x-tunnel for (.+?):(.+?) proxy fail\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"code/default/smart_router/local/smart_route.py","lineNumber":271,"sourceCode":"        raise XTunnelNotRunning()\n\n    # xlog.debug(\"do_socks %r connect to %s:%d conn_id:%d\", client_address, host, port, conn_id)\n    if left_buf:\n        g.x_tunnel.global_var.session.conn_list[conn_id].transfer_received_data(left_buf)\n    g.x_tunnel.global_var.session.conn_list[conn_id].start(block=True)\n\n\ndef do_unwrap_socks(sock, host, port, client_address, req, left_buf=b\"\"):\n    if not g.x_tunnel:\n        return\n\n    try:\n        remote_sock = socks.create_connection(\n            (host, port),\n            proxy_type=\"socks5h\", proxy_addr=\"127.0.0.1\", proxy_port=g.x_tunnel_socks_port, timeout=15\n        )\n    except Exception as e:\n        xlog.warn(\"do_unwrap_socks connect to x-tunnel for %s:%d proxy fail.\", host, port)\n        return\n\n    if isinstance(req.connection, ssl.SSLSocket):\n        try:\n            remote_ssl_sock = ssl_context.wrap_socket(remote_sock, server_hostname=host)\n        except:\n            xlog.warn(\"do_unwrap_socks ssl_wrap for %s:%d proxy fail.\", host, port)\n            return\n    else:\n        remote_ssl_sock = remote_sock\n\n    # avoid close by req.__del__\n    req.rfile._close = False\n    req.wfile._close = False\n    req.connection = None\n\n    if not isinstance(sock, SocketWrap):\n        sock = SocketWrap(sock, client_address[0], client_address[1])","sourceCodeStart":253,"sourceCodeEnd":289,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/smart_router/local/smart_route.py#L253-L289","documentation":"do_unwrap_socks could not create a SOCKS5 connection to the local x-tunnel SOCKS entry (127.0.0.1:g.x_tunnel_socks_port) within 15s; the unwrap attempt is abandoned.","triggerScenarios":"socks.create_connection to 127.0.0.1:x_tunnel_socks_port fails: the local x-tunnel SOCKS listener is not running, wrong port, or connect timeout (15s).","commonSituations":"x-tunnel SOCKS component not started, port misconfigured in g.x_tunnel_socks_port, firewall/loopback restrictions, x-tunnel process crashed.","solutions":["Confirm the x-tunnel client is running and its SOCKS port matches g.x_tunnel_socks_port","Check the port is listening: ss -lntp | grep <port>","Restart x-tunnel if the listener died","Raise the 15s timeout on slow machines if startup is racing"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"import socket as s; s.create_connection(('127.0.0.1', port), 1)  # probe listener first","typeGuard":null,"tryCatchPattern":"Retry create_connection once after short delay; fall back to other rules on second failure.","preventionTips":["Verify the local x-tunnel SOCKS port is listening before routing","Keep x-tunnel client process supervised"],"tags":["x-tunnel","socks5","local-proxy","connection-refused"],"backgroundTag":"local-proxy-connect-failed","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}