egametang/ET · error · Exception
socket error: {e.LastOperation}
Error message
socket error: {e.LastOperation} What it means
TService.OnComplete dispatches SocketAsyncEventArgs completions by LastOperation. The acceptor only expects Accept completions; any other operation (Receive/Send/Disconnect) is treated as an impossible state and throws.
Source
Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Network/TService.cs:78
this.acceptor.Listen(1000);
this.AcceptAsync();
}
public override IPEndPoint GetBindPoint()
{
return this.acceptor.LocalEndPoint as IPEndPoint;
}
private void OnComplete(object sender, SocketAsyncEventArgs e)
{
switch (e.LastOperation)
{
case SocketAsyncOperation.Accept:
this.Queue.Enqueue(new TArgs() {SocketAsyncEventArgs = e});
break;
default:
throw new Exception($"socket error: {e.LastOperation}");
}
}
private void OnAcceptComplete(SocketError socketError, Socket acceptSocket)
{
if (this.acceptor == null)
{
return;
}
if (socketError != SocketError.Success)
{
Log.Error($"accept error {socketError}");
this.AcceptAsync();
return;
}
tryView on GitHub (pinned to 5cab01f7a8)
Solutions
- Confirm only accept-related SocketAsyncEventArgs use this OnComplete handler.
- Log and ignore unexpected operations instead of crashing the accept loop.
- Audit the Completed subscription wiring for the acceptor vs channels.
Example fix
// before
default: throw new Exception($"socket error: {e.LastOperation}");
// after
default: Log.Error($"unexpected socket op on acceptor: {e.LastOperation}"); break; Defensive patterns
Strategy: type-guard
Validate before calling
null
Type guard
static bool IsExpectedAcceptorOp(SocketAsyncOperation op) => op == SocketAsyncOperation.Accept;
Try / catch
null
Prevention
- Only attach the acceptor's Completed handler to accept args.
- Log unexpected ops instead of crashing the accept loop.
- Audit args wiring when adding new socket operations.
When it happens
Trigger: A SocketAsyncEventArgs wired with the wrong operation reaches OnComplete, or a Send/Receive event was accidentally attached to the acceptor's handler.
Common situations: A reuse/programming bug in the socket wiring, or a framework regression where a channel's args bubble up to the acceptor's Completed handler.
Related errors
- socket set buffer error: {this.sendBuffer.First.Length}, {th
- bind error: {ipEndPoint}
- {e.LastOperation}
- bind error: {ipEndPoint}
- recv packet size error, 可能是外网探测端口: {this.packetSize}
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/4c137a6caf500048.
Report an issue: GitHub.