{"record":{"id":"d4a049ee155b4b04","repo":"egametang/ET","slug":"recv-packet-size-error-this-packetsiz","errorCode":null,"errorMessage":"recv packet size error, 可能是外网探测端口: {this.packetSize}","messagePattern":"recv packet size error, 可能是外网探测端口: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"Packages/cn.etetet.core/Scripts/Core/Share/Network/PacketParser.cs","lineNumber":50,"sourceCode":"\t\t\t{\n\t\t\t\tswitch (this.state)\n\t\t\t\t{\n\t\t\t\t\tcase ParserState.PacketSize:\n\t\t\t\t\t{\n\t\t\t\t\t\tif (this.service.ServiceType == ServiceType.Inner)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (this.buffer.Length < InnerPacketSizeLength)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmemoryBuffer = null;\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthis.buffer.Read(this.cache, 0, InnerPacketSizeLength);\n\n\t\t\t\t\t\t\tthis.packetSize = BitConverter.ToInt32(this.cache, 0);\n\t\t\t\t\t\t\tif (this.packetSize > ushort.MaxValue * 16 || this.packetSize < Packet.MinPacketSize)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tthrow new Exception($\"recv packet size error, 可能是外网探测端口: {this.packetSize}\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (this.buffer.Length < OuterPacketSizeLength)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmemoryBuffer = null;\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tthis.buffer.Read(this.cache, 0, OuterPacketSizeLength);\n\n\t\t\t\t\t\t\tthis.packetSize = BitConverter.ToUInt16(this.cache, 0);\n\t\t\t\t\t\t\tif (this.packetSize < Packet.MinPacketSize)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tthrow new Exception($\"recv packet size error, 可能是外网探测端口: {this.packetSize}\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.core/Scripts/Core/Share/Network/PacketParser.cs#L32-L68","documentation":"PacketParser reads a 4-byte inner (server-to-server) packet size and validates it against [Packet.MinPacketSize, ushort.MaxValue*16]. A value outside that range means the stream is not a valid inner protocol frame — the comment suggests an external probe hitting the inner port.","triggerScenarios":"An outer/client connection or a port scanner sending bytes to the inner port, a desync after a dropped packet, or two protocols multiplexed on one port.","commonSituations":"Firewall/health-check probing the inner port, client connecting to the inner port by mistake, or memory corruption in the read buffer.","solutions":["Keep the inner port on a private/trusted network and never expose it publicly.","Verify the peer is speaking the inner protocol (auth/handshake) before framing.","On error, close/reset the connection rather than crashing the service."],"exampleFix":"// before\nif (packetSize > ushort.MaxValue * 16 || packetSize < Packet.MinPacketSize)\n    throw new Exception(...);\n// after\nif (packetSize > ushort.MaxValue * 16 || packetSize < Packet.MinPacketSize) {\n    Log.Error($\"bad inner frame {packetSize}, likely probing\");\n    this.service.RemoveChannel(channelId);\n    return false;\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"static bool IsValidInnerPacketSize(int s) => s >= Packet.MinPacketSize && s <= ushort.MaxValue * 16;","tryCatchPattern":"try { if (!parser.Parse(out var mb))) return; }\ncatch (Exception e) when (e.Message.Contains(\"recv packet size error\"))\n{ service.RemoveChannel(channelId); Log.Error(e); }","preventionTips":["Keep the inner port off the public internet.","Authenticate/handshake before framing inner traffic.","Treat a bad frame as a reason to drop the connection, not crash."],"tags":["network","packet","tcp","csharp"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}