{"record":{"id":"144ef8f66db94298","repo":"dotnet/yarp","slug":"expected-to-receive-endofmessage-true","errorCode":null,"errorMessage":"Expected to receive EndOfMessage = true.","messagePattern":"Expected to receive EndOfMessage = true\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"testassets/TestClient/Scenarios/WebSocketsScenario.cs","lineNumber":48,"sourceCode":"        stopwatch.Restart();\n        for (var i = 0; i < 256; i++)\n        {\n            var textToSend = $\"Hello {i}\";\n            var numBytes = Encoding.UTF8.GetBytes(textToSend, buffer.AsSpan());\n            await client.SendAsync(new ArraySegment<byte>(buffer, 0, numBytes),\n                WebSocketMessageType.Text,\n                endOfMessage: true,\n                cancellation);\n\n            var message = await client.ReceiveAsync(buffer, cancellation);\n            if (message.MessageType != WebSocketMessageType.Text)\n            {\n                throw new Exception($\"Expected to receive a text message, got '{message.MessageType}' instead.\");\n            }\n\n            if (!message.EndOfMessage)\n            {\n                throw new Exception(\"Expected to receive EndOfMessage = true.\");\n            }\n\n            var text = Encoding.UTF8.GetString(buffer.AsSpan(0, message.Count));\n            if (text != textToSend)\n            {\n                throw new Exception($\"Expected to receive '{textToSend}', but got '{text}'.\");\n            }\n\n            Console.Write(\".\");\n        }\n\n        Console.WriteLine();\n        Console.WriteLine($\"Completed 256 text messages in {stopwatch.ElapsedMilliseconds} ms.\");\n\n        Console.WriteLine(\"Sending binary messages...\");\n        stopwatch.Restart();\n        for (var i = 0; i < 256; i++)\n        {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/testassets/TestClient/Scenarios/WebSocketsScenario.cs#L30-L66","documentation":"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.","triggerScenarios":"Running WebSocketsScenario against an endpoint or intermediary that fragments a small message into multiple frames, so the first ReceiveAsync sees EndOfMessage false.","commonSituations":"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.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// If you adapt the scenario, reassemble fragmented messages instead of asserting EndOfMessage.\nasync Task<(string text, WebSocketMessageType type)> ReceiveFullAsync(WebSocket ws, byte[] buf, CancellationToken ct) {\n    using var ms = new MemoryStream();\n    WebSocketReceiveResult r;\n    do {\n        r = await ws.ReceiveAsync(buf, ct);\n        ms.Write(buf, 0, r.Count);\n        if (r.MessageType == WebSocketMessageType.Close) throw new IOException(\"peer closed\");\n    } while (!r.EndOfMessage);\n    return (Encoding.UTF8.GetString(ms.ToArray()), r.MessageType);\n}","typeGuard":null,"tryCatchPattern":"try { await WebSocketsScenario.RunAsync(client, args, cancellation); }\ncatch (Exception ex) when (ex.Message.Contains(\"EndOfMessage\")) {\n    Console.Error.WriteLine(\"Frames arrived fragmented; disable permessage-deflate or remove re-chunking proxy.\");\n    return 1;\n}","preventionTips":["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."],"tags":["test","websockets","scenario","framing","test-client","yarp"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}