{"record":{"id":"2032a4c1ba08ad7e","repo":"XX-net/XX-Net","slug":"xtunnelnotrunning","errorCode":null,"errorMessage":"XTunnelNotRunning","messagePattern":"XTunnelNotRunning","errorType":"exception","errorClass":"XTunnelNotRunning","httpStatus":null,"severity":"warning","filePath":"code/default/smart_router/local/smart_route.py","lineNumber":249,"sourceCode":"\n    xlog.debug(\"host:%s:%d redirect_https connect %s success\", host, port, remote_sock.ip)\n\n    if left_buf:\n        ssl_sock.send(left_buf)\n    sw = SocketWrap(ssl_sock, remote_sock.ip, port, host)\n    sock.recved_times = 3\n    g.pipe_socks.add_socks(sock, sw)\n\n\ndef do_socks(sock, host, port, client_address, left_buf=b\"\"):\n    if not g.x_tunnel:\n        raise XTunnelNotRunning()\n\n    try:\n        conn_id = g.x_tunnel.proxy_session.create_conn(sock, host, port, True)\n    except Exception as e:\n        xlog.warn(\"do_sock to %s:%d, x_tunnel fail:%r\", host, port, e)\n        raise XTunnelNotRunning()\n\n    if not conn_id:\n        xlog.warn(\"x_tunnel create conn fail\")\n        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),","sourceCodeStart":231,"sourceCodeEnd":267,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/smart_router/local/smart_route.py#L231-L267","documentation":"do_socks raises XTunnelNotRunning when the X-Tunnel proxy is unavailable. This first site fires when accessing g.x_tunnel.proxy_session fails or is unset — i.e. the X-Tunnel subsystem was never started or has already shut down, so attribute access on None raises and the except converts it to XTunnelNotRunning, letting try_loop fall back to another route.","triggerScenarios":"A SOCKS connection is routed to the X-Tunnel strategy while g.x_tunnel is None (X-Tunnel not logged in / not enabled), or proxy_session is missing because the tunnel stopped.","commonSituations":"X-Tunnel account not configured or login failed at startup, tunnel service shut down mid-run, deployment where only GAE proxy is enabled but routing rules still send traffic to X-Tunnel.","solutions":["Ensure X-Tunnel is enabled and logged in so g.x_tunnel.proxy_session exists before traffic is routed to it","Check X-Tunnel login status/log for the root cause of the tunnel not running","Adjust smart_router rules or goagent config so socks traffic prefers a working strategy (direct/GAE) when tunnel is down","Catch XTunnelNotRunning in try_loop to fall back to the next route (this is the designed behavior)"],"exampleFix":"// conceptual\n# before\nconn_id = g.x_tunnel.proxy_session.create_conn(sock, host, port, True)\n\n# after\nif not g.x_tunnel or not getattr(g.x_tunnel, 'proxy_session', None):\n    raise XTunnelNotRunning()  # explicit check instead of relying on AttributeError","handlingStrategy":"type-guard","validationCode":"def x_tunnel_ready():\n    return bool(getattr(g, 'x_tunnel', None) and getattr(g.x_tunnel, 'proxy_session', None))","typeGuard":"def x_tunnel_ready() -> bool:\n    xt = getattr(g, 'x_tunnel', None)\n    return xt is not None and getattr(xt, 'proxy_session', None) is not None","tryCatchPattern":"try:\n    do_socks(...)\nexcept XTunnelNotRunning:\n    try_next_strategy(sock, host, port)","preventionTips":["Check g.x_tunnel/proxy_session before adding X-Tunnel to rule_list","Monitor tunnel login state and remove the strategy when down"],"tags":["x-tunnel","socks-proxy","smart-router","service-unavailable"],"backgroundTag":"proxy-service-unavailable","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}