egametang/ET · error · Exception

bufferList length < count, {Length} {count}

Error message

bufferList length < count, {Length} {count}

What it means

CircularBuffer.Read(Stream, int) copies `count` bytes into a destination stream. It throws when the requested count exceeds the buffer's current Length, i.e. the caller asked for data that has not arrived yet.

Source

Thrown at Packages/cn.etetet.core/Scripts/Core/Share/Network/Circularbuffer.cs:120

		//	    sendSize = (int)buffLength;
		//    }
		//	
		//    await stream.WriteAsync(this.First, this.FirstIndex, sendSize);
		//    
		//    this.FirstIndex += sendSize;
		//    if (this.FirstIndex == this.ChunkSize)
		//    {
		//	    this.FirstIndex = 0;
		//	    this.RemoveFirst();
		//    }
		//}

	    // 从CircularBuffer读到stream
	    public void Read(Stream stream, int count)
	    {
		    if (count > this.Length)
		    {
			    throw new Exception($"bufferList length < count, {Length} {count}");
		    }

		    int alreadyCopyCount = 0;
		    while (alreadyCopyCount < count)
		    {
			    int n = count - alreadyCopyCount;
			    if (ChunkSize - this.FirstIndex > n)
			    {
				    stream.Write(this.First, this.FirstIndex, n);
				    this.FirstIndex += n;
				    alreadyCopyCount += n;
			    }
			    else
			    {
				    stream.Write(this.First, this.FirstIndex, ChunkSize - this.FirstIndex);
				    alreadyCopyCount += ChunkSize - this.FirstIndex;
				    this.FirstIndex = 0;
				    this.RemoveFirst();

View on GitHub (pinned to 5cab01f7a8)

Solutions

  1. Always check buffer.Length >= count before calling Read (the PacketParser already does this pattern).
  2. Return/false-wait until enough bytes accumulate instead of throwing.
  3. Re-derive count from a freshly parsed size header.

Example fix

// before
buffer.Read(stream, expectedCount);
// after
if (buffer.Length < expectedCount) return false;
buffer.Read(stream, expectedCount);
Defensive patterns

Strategy: validation

Validate before calling

if (buffer.Length < count) return false; // not enough data yet
buffer.Read(stream, count);

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Reading a packet body before all its bytes are buffered, miscalculating packetSize, or a producer/consumer race where the reader outran the network writer.

Common situations: Packet parser using a stale packetSize after a malformed header, or two readers draining the same buffer.

Related errors


AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13). Data as JSON: /api/errors/e21486e1116dd88e. Report an issue: GitHub.