egametang/ET · error · Exception
socket set buffer error: {this.sendBuffer.First.Length}, {th
Error message
socket set buffer error: {this.sendBuffer.First.Length}, {this.sendBuffer.FirstIndex} What it means
TChannel.StartSend wraps any exception from outArgs.SetBuffer / socket.SendAsync with the sendBuffer chunk length and FirstIndex. SetBuffer throws when offset/count is outside the underlying array bounds, and SendAsync throws when the socket is in a bad/closed state.
Source
Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Network/TChannel.cs:311
this.isSending = true;
int sendSize = this.sendBuffer.ChunkSize - this.sendBuffer.FirstIndex;
if (sendSize > this.sendBuffer.Length)
{
sendSize = (int)this.sendBuffer.Length;
}
this.outArgs.SetBuffer(this.sendBuffer.First, this.sendBuffer.FirstIndex, sendSize);
if (this.socket.SendAsync(this.outArgs))
{
return;
}
HandleSend(this.outArgs);
}
catch (Exception e)
{
throw new Exception($"socket set buffer error: {this.sendBuffer.First.Length}, {this.sendBuffer.FirstIndex}", e);
}
}
}
public void OnSendComplete(SocketAsyncEventArgs o)
{
HandleSend(o);
this.isSending = false;
this.Service.Queue.Enqueue(new TArgs() { Op = TcpOp.StartSend, ChannelId = this.Id});
}
private void HandleSend(SocketAsyncEventArgs e)
{
if (this.socket == null)
{
return;View on GitHub (pinned to 5cab01f7a8)
Solutions
- Re-check socket != null inside the loop (the code already does) and also after SendAsync failures.
- Ensure FirstIndex never exceeds sendBuffer.First.Length before SetBuffer.
- Treat the wrapped inner exception as the real cause and surface it.
Example fix
// before this.outArgs.SetBuffer(this.sendBuffer.First, this.sendBuffer.FirstIndex, sendSize); // after if (this.sendBuffer.FirstIndex + sendSize > this.sendBuffer.First.Length) sendSize = this.sendBuffer.First.Length - this.sendBuffer.FirstIndex; this.outArgs.SetBuffer(this.sendBuffer.First, this.sendBuffer.FirstIndex, sendSize);
Defensive patterns
Strategy: try-catch
Validate before calling
if (sendBuffer.FirstIndex + sendSize > sendBuffer.First.Length)
sendSize = sendBuffer.First.Length - sendBuffer.FirstIndex; Type guard
null
Try / catch
try { StartSend(); }
catch (Exception e) when (e.Message.StartsWith("socket set buffer error"))
{ OnError(...); } Prevention
- Clamp sendSize to the remaining chunk length before SetBuffer.
- Re-check socket != null after async failures.
- Surface the wrapped inner exception for diagnosis.
When it happens
Trigger: sendBuffer.FirstIndex advanced past the chunk length (buffer accounting bug), or the socket was disposed between the length check and SendAsync.
Common situations: Concurrent dispose of the channel mid-send, a circular-buffer index that went out of range, or a reused SocketAsyncEventArgs after teardown.
Related errors
- bind error: {ipEndPoint}
- socket error: {e.LastOperation}
- {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/add9140d132ccdbd.
Report an issue: GitHub.