{"record":{"id":"2161a0a266696990","repo":"XX-net/XX-Net","slug":"x-tunnel-request-balance-fail-when-create-conn-s-2161a0","errorCode":null,"errorMessage":"x-tunnel request_balance fail when create_conn:%s","messagePattern":"x-tunnel request_balance fail when create_conn:(.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"code/default/x_tunnel/local/proxy_session.py","lineNumber":1348,"sourceCode":"\n\nlogin_lock = threading.Lock()\n\n\ndef login_process():\n    if not g.session:\n        return\n\n    with login_lock:\n        if not (g.config.login_account and g.config.login_password):\n            xlog.debug(\"x-tunnel no account\")\n            return False\n\n        if not g.server_host:\n            xlog.debug(\"session not running, try login..\")\n            res, reason = request_balance(g.config.login_account, g.config.login_password)\n            if not res:\n                xlog.warn(\"x-tunnel request_balance fail when create_conn:%s\", reason)\n                return False\n\n        if time.time() - g.session.last_send_time > 5 * 60 - 5:\n            xlog.info(\"session timeout, reset it.\")\n            g.session.stop()\n\n        if g.tls_relay_front:\n            g.tls_relay_front.set_x_tunnel_account(g.config.login_account, g.config.login_password)\n        if g.seley_front:\n            g.seley_front.set_x_tunnel_account(g.config.login_account, g.config.login_password)\n\n        if not g.session.running:\n            return g.session.start()\n\n    return True\n\n\ndef create_conn(sock, host, port, log=False):","sourceCodeStart":1330,"sourceCodeEnd":1366,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/x_tunnel/local/proxy_session.py#L1330-L1366","documentation":"Logged by login_process (invoked from try_loop, roundtrip_task, create_conn) when the session is not yet running (g.server_host empty) and an attempt to (re)authenticate via request_balance fails. The reason string from request_balance explains the underlying failure. create_conn then returns False, so no connection is established this round.","triggerScenarios":"g.server_host is empty (first start or after stop/reset) and request_balance(login_account, login_password) returns a non-True result — network error reaching the balance API, auth rejection, or malformed response. Any caller that needs a connection (roundtrip_task, create_conn, try_loop) hits this.","commonSituations":"Startup with no cached session, wrong credentials in config, the balance/auth server being unreachable (DNS, GFW interference, outage), or system clock skew breaking auth.","solutions":["Check the embedded reason string; if auth-related, correct login_account/login_password in the x_tunnel config.","Confirm network access to the login/balance API host (curl it directly) and fix DNS/proxy issues.","Retry — try_loop will re-attempt login on subsequent iterations; if it never succeeds, inspect firewall rules blocking the API endpoint.","Update XX-Net/x_tunnel if the API endpoint or protocol changed (server-side changes break old clients)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Persist the last good server_host so cold starts still have a session.","Validate credentials at config load time.","Wrap create_conn callers in a retry loop with backoff; treat False as retryable."],"tags":["x-tunnel","login","auth","connection","startup"],"backgroundTag":"authentication-failed","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}