dotnet/yarp · error · Exception
Expected to receive EndOfMessage = true.
Error message
Expected to receive EndOfMessage = true.
What it means
Asserted in WebSocketsScenario when a received frame's EndOfMessage flag is false. Each test message is small and sent as a single complete frame, so the echo must also arrive as a single frame with EndOfMessage true. A false flag means the frame was fragmented across reads, which the scenario does not reassemble.
Source
Thrown at testassets/TestClient/Scenarios/WebSocketsScenario.cs:48
stopwatch.Restart();
for (var i = 0; i < 256; i++)
{
var textToSend = $"Hello {i}";
var numBytes = Encoding.UTF8.GetBytes(textToSend, buffer.AsSpan());
await client.SendAsync(new ArraySegment<byte>(buffer, 0, numBytes),
WebSocketMessageType.Text,
endOfMessage: true,
cancellation);
var message = await client.ReceiveAsync(buffer, cancellation);
if (message.MessageType != WebSocketMessageType.Text)
{
throw new Exception($"Expected to receive a text message, got '{message.MessageType}' instead.");
}
if (!message.EndOfMessage)
{
throw new Exception("Expected to receive EndOfMessage = true.");
}
var text = Encoding.UTF8.GetString(buffer.AsSpan(0, message.Count));
if (text != textToSend)
{
throw new Exception($"Expected to receive '{textToSend}', but got '{text}'.");
}
Console.Write(".");
}
Console.WriteLine();
Console.WriteLine($"Completed 256 text messages in {stopwatch.ElapsedMilliseconds} ms.");
Console.WriteLine("Sending binary messages...");
stopwatch.Restart();
for (var i = 0; i < 256; i++)
{View on GitHub (pinned to bd11867bee)
Solutions
- Use the matching test backend that returns single complete frames.
- Disable WebSocket extensions (e.g. permessage-deflate) on the client or server if they cause fragmentation.
- Remove or reconfigure intermediaries that re-chunk frames.
- If you adapt the scenario, loop ReceiveAsync until EndOfMessage to support fragmentation.
Defensive patterns
Strategy: validation
Validate before calling
// If you adapt the scenario, reassemble fragmented messages instead of asserting EndOfMessage.
async Task<(string text, WebSocketMessageType type)> ReceiveFullAsync(WebSocket ws, byte[] buf, CancellationToken ct) {
using var ms = new MemoryStream();
WebSocketReceiveResult r;
do {
r = await ws.ReceiveAsync(buf, ct);
ms.Write(buf, 0, r.Count);
if (r.MessageType == WebSocketMessageType.Close) throw new IOException("peer closed");
} while (!r.EndOfMessage);
return (Encoding.UTF8.GetString(ms.ToArray()), r.MessageType);
} Try / catch
try { await WebSocketsScenario.RunAsync(client, args, cancellation); }
catch (Exception ex) when (ex.Message.Contains("EndOfMessage")) {
Console.Error.WriteLine("Frames arrived fragmented; disable permessage-deflate or remove re-chunking proxy.");
return 1;
} Prevention
- Disable WebSocket extensions (permessage-deflate) if they fragment small messages.
- Remove intermediaries that re-chunk frames.
- If you control the scenario, loop until EndOfMessage rather than asserting it.
When it happens
Trigger: Running WebSocketsScenario against an endpoint or intermediary that fragments a small message into multiple frames, so the first ReceiveAsync sees EndOfMessage false.
Common situations: A proxy that re-chunks WebSocket frames; an echo backend that splits messages; an extension (permessage-deflate) that changes framing; large effective frame size after compression causing fragmentation.
Related errors
- Expected to receive a text message, got '{message.MessageTyp
- Expected to receive '{textToSend}', but got '{text}'.
- Expected status 409 Conflict!
- Expected status 101 Switching Protocols!
- Read {read} bytes, expected 0 after sending Goodbye.
AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13).
Data as JSON: /api/errors/144ef8f66db94298.
Report an issue: GitHub.