egametang/ET · critical · Exception
recv packet size error, 可能是外网探测端口: {this.packetSize}
Error message
recv packet size error, 可能是外网探测端口: {this.packetSize} What it means
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.
Source
Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Network/PacketParser.cs:50
{
switch (this.state)
{
case ParserState.PacketSize:
{
if (this.service.ServiceType == ServiceType.Inner)
{
if (this.buffer.Length < InnerPacketSizeLength)
{
memoryBuffer = null;
return false;
}
this.buffer.Read(this.cache, 0, InnerPacketSizeLength);
this.packetSize = BitConverter.ToInt32(this.cache, 0);
if (this.packetSize > ushort.MaxValue * 16 || this.packetSize < Packet.MinPacketSize)
{
throw new Exception($"recv packet size error, 可能是外网探测端口: {this.packetSize}");
}
}
else
{
if (this.buffer.Length < OuterPacketSizeLength)
{
memoryBuffer = null;
return false;
}
this.buffer.Read(this.cache, 0, OuterPacketSizeLength);
this.packetSize = BitConverter.ToUInt16(this.cache, 0);
if (this.packetSize < Packet.MinPacketSize)
{
throw new Exception($"recv packet size error, 可能是外网探测端口: {this.packetSize}");
}
}View on GitHub (pinned to 5cab01f7a8)
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.
Example fix
// before
if (packetSize > ushort.MaxValue * 16 || packetSize < Packet.MinPacketSize)
throw new Exception(...);
// after
if (packetSize > ushort.MaxValue * 16 || packetSize < Packet.MinPacketSize) {
Log.Error($"bad inner frame {packetSize}, likely probing");
this.service.RemoveChannel(channelId);
return false;
} Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
static bool IsValidInnerPacketSize(int s) => s >= Packet.MinPacketSize && s <= ushort.MaxValue * 16;
Try / catch
try { if (!parser.Parse(out var mb))) return; }
catch (Exception e) when (e.Message.Contains("recv packet size error"))
{ service.RemoveChannel(channelId); Log.Error(e); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Firewall/health-check probing the inner port, client connecting to the inner port by mistake, or memory corruption in the read buffer.
Related errors
- send packet too large: {stream.Length} {stream.Position}
- TChannel已经被Dispose, 不能发送消息
- socket set buffer error: {this.sendBuffer.First.Length}, {th
- bind error: {ipEndPoint}
- socket error: {e.LastOperation}
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/d4a049ee155b4b04.
Report an issue: GitHub.