{"record":{"id":"78282af84acd5ca6","repo":"egametang/ET","slug":"get-router-fail-netcomponent-root-id-address","errorCode":null,"errorMessage":"get router fail: {netComponent.Root().Id} {address}","messagePattern":"get router fail: (.+?) (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Packages/cn.etetet.login/Scripts/Hotfix/Client/NetClient/Router/RouterHelper.cs","lineNumber":18,"sourceCode":"using System;\nusing System.Net;\n\nnamespace ET.Client\n{\n    public static partial class RouterHelper\n    {\n        // 注册router\n        public static async ETTask<Session> CreateRouterSession(this NetComponent netComponent, IPEndPoint address, string account, string password)\n        {\n            EntityRef<NetComponent> netComponentRef = netComponent;\n            uint localConn = (uint)(account.GetLongHashCode() ^ password.GetLongHashCode() ^ RandomGenerator.RandUInt32());\n            (uint recvLocalConn, IPEndPoint routerAddress) = await GetRouterAddress(netComponent, address, localConn, 0);\n            \n            netComponent = netComponentRef;\n            if (recvLocalConn == 0)\n            {\n                throw new Exception($\"get router fail: {netComponent.Root().Id} {address}\");\n            }\n            \n            Log.Info($\"get router: {recvLocalConn} {routerAddress}\");\n\n            Session routerSession = netComponent.Create(routerAddress, address, recvLocalConn);\n            routerSession.AddComponent<PingComponent>();\n            routerSession.AddComponent<RouterCheckComponent>();\n            \n            return routerSession;\n        }\n        \n        public static async ETTask<(uint, IPEndPoint)> GetRouterAddress(this NetComponent netComponent, IPEndPoint address, uint localConn, uint remoteConn)\n        {\n            EntityRef<NetComponent> netComponentRef = netComponent;\n            Log.Info($\"start get router address: {netComponent.Root().Id} {address} {localConn} {remoteConn}\");\n            //return (RandomHelper.RandUInt32(), address);\n            RouterAddressComponent routerAddressComponent = netComponent.Root().GetComponent<RouterAddressComponent>();\n            IPEndPoint routerInfo = routerAddressComponent.GetAddress();","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.login/Scripts/Hotfix/Client/NetClient/Router/RouterHelper.cs#L1-L36","documentation":"Thrown by RouterHelper.CreateRouterSession when the router SYN handshake returns recvLocalConn == 0. Looking at the Connect method, this happens when the retry loop exhausts 20 attempts (sending RouterSYN every 300ms) or when the TimerComponent is destroyed mid-handshake. It means the router server never acknowledged the connection request.","triggerScenarios":"CreateRouterSession calls GetRouterAddress -> Connect, which sends up to 20 SYN packets to the router address. If the router never responds with an ACK (routerConnector.Flag stays 0), or the TimerComponent becomes null, Connect returns 0 and CreateRouterSession throws.","commonSituations":"Router server is down or unreachable at the configured address. Firewall blocks UDP traffic (KCP-based router). Router address is misconfigured (wrong IP/port). Network latency exceeds the 20-retry * 300ms window (~6 seconds). RouterConnector component was disposed before the handshake completed.","solutions":["Verify the router server is running and reachable at the configured IP/port — check UDP connectivity and firewall rules.","Check the router address configuration (RouterAddressComponent.GetAddress returns the correct endpoint).","If network conditions are poor, consider increasing the retry count or interval in the Connect method (currently 20 retries at 300ms).","Ensure the NetComponent and its TimerComponent are not disposed during the handshake."],"exampleFix":"// before: 20 retries at 300ms\nint count = 20;\n// after: increase retries for unstable networks\nint count = 40;","handlingStrategy":"retry","validationCode":"// Validate router reachability before full handshake\nIPEndPoint routerAddr = netComponent.Root().GetComponent<RouterAddressComponent>().GetAddress();\nif (routerAddr == null)\n{\n    Log.Error(\"Router address component returned null endpoint\");\n    return null;\n}","typeGuard":null,"tryCatchPattern":"try { Session s = await netComponent.CreateRouterSession(address, account, password); } catch (Exception e) { Log.Error($\"Router connection failed: {e.Message}\"); /* show user retry prompt */ }","preventionTips":["Verify the router server is running and UDP traffic is allowed through the firewall before launching.","Monitor router health and surface connection failures to the user with a retry option.","Ensure the NetComponent and TimerComponent are not disposed during the router handshake."],"tags":["network","router","kcp","connection","login"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}