dotnet/orleans · error · ArgumentOutOfRangeException
Message size is too big. MessageSize: {size}
Error message
Message size is too big. MessageSize: {size} What it means
EventHubQueueCache.GetSegment throws ArgumentOutOfRangeException when a single Event Hub message's serialized size exceeds the capacity of a freshly allocated FixedSizeBuffer block. Each block from the buffer pool has a fixed maximum capacity, and if a message (offset string + partition key + properties + payload) is larger than that capacity, no segment can ever satisfy the request — so the adapter fails fast rather than silently dropping or truncating the message. The exception message includes the requested size for diagnostics.
Source
Thrown at src/Azure/Orleans.Streaming.EventHubs/Providers/Streams/EventHub/EventHubQueueCache.cs:229
return true;
}
private ArraySegment<byte> GetSegment(int size)
{
// get segment from current block
ArraySegment<byte> segment;
if (currentBuffer == null || !currentBuffer.TryGetSegment(size, out segment))
{
// no block or block full, get new block and try again
var newBuffer = bufferPool.Allocate();
// if this fails with a clean block, then requested size is too big; return the
// unused block to the pool and fail. Registering it with the eviction strategy
// before confirming the segment fits would leak it, because a batch that never
// commits is never reclaimed by the purge-time logic.
if (!newBuffer.TryGetSegment(size, out segment))
{
newBuffer.Dispose();
throw new ArgumentOutOfRangeException(nameof(size), $"Message size is too big. MessageSize: {size}");
}
currentBuffer = newBuffer;
//call EvictionStrategy's OnBlockAllocated method
this.evictionStrategy.OnBlockAllocated(currentBuffer);
}
return segment;
}
private readonly struct DateTimeLogRecord(DateTime ts)
{
public override string ToString() => LogFormatter.PrintDate(ts);
}
[LoggerMessage(
Level = LogLevel.Debug,
Message = "CachePeriod: EnqueueTimeUtc: {OldestEnqueueTimeUtc} to {NewestEnqueueTimeUtc}, DequeueTimeUtc: {OldestDequeueTimeUtc} to {NewestDequeueTimeUtc}"
)]
private partial void LogDebugCachePeriod(View on GitHub (pinned to fca799fa70)
Solutions
- Reduce the size of events being published — split large payloads into multiple smaller events or compress the payload.
- If the buffer pool block size is configurable in your setup, increase it to accommodate the maximum expected message size.
- Check the EventData properties dictionary — large custom metadata can significantly increase the serialized size beyond the payload alone.
- Monitor Event Hub message sizes in production and set up alerts for messages approaching the configured block size limit.
Example fix
// before — publishing a large payload as a single event
var largePayload = new byte[900_000]; // close to block limit
await stream.OnNextAsync(new LargeEvent { Data = largePayload });
// after — split or compress large payloads
var chunks = SplitIntoChunks(largePayload, chunkSize: 100_000);
foreach (var chunk in chunks)
{
await stream.OnNextAsync(new ChunkedEvent { Chunk = chunk, Index = i++ });
}
// or compress:
var compressed = Compress(largePayload);
await stream.OnNextAsync(new CompressedEvent { Data = compressed }); Defensive patterns
Strategy: validation
Validate before calling
// Validate message size before publishing:
static void EnsureEventSizeWithinLimit<T>(T evt, Orleans.Serialization.Serializer serializer, int maxSegmentSize)
{
var payloadBytes = serializer.SerializeToArray(evt);
if (payloadBytes.Length > maxSegmentSize)
throw new InvalidOperationException(
$"Event serialized size {payloadBytes.Length} exceeds cache block limit {maxSegmentSize}. " +
"Split the payload or increase the buffer pool block size.");
} Prevention
- Monitor Event Hub message sizes and set alerts for messages approaching the buffer pool block size.
- Split large payloads into multiple smaller events or compress them before publishing.
- Keep EventData properties dictionaries small — large metadata inflates serialized size.
- Know the FixedSizeBuffer block size in your cache configuration and ensure messages fit within it.
When it happens
Trigger: An incoming EventData whose total serialized size (computed in EventHubDataAdapter.EncodeMessageIntoSegment as the sum of offset, partition key, properties, and payload) exceeds the FixedSizeBuffer block size. This is determined by the buffer pool configuration (typically the block size is fixed by PooledQueueCache/FixedSizeBuffer). Large messages (e.g., Event Hub's max of 1 MB per event, or a configured lower limit) can trigger this.
Common situations: Publishing large events (near or above the Event Hub 1 MB limit) through an Orleans Event Hub stream; a spike in message size due to large serialized objects or large metadata/properties dictionaries; a buffer pool configured with an unusually small block size via custom EventHubStreamCachePressureOptions or a custom IObjectPool<FixedSizeBuffer>; Azure Event Hub capturing large payloads from IoT devices or bulk upload scenarios.
Related errors
AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13).
Data as JSON: /api/errors/9768b2b3f746e2aa.
Report an issue: GitHub.