{"record":{"id":"0a10813abfba8d41","repo":"dotnet/yarp","slug":"read-read-bytes-expected-1","errorCode":null,"errorMessage":"Read {read} bytes, expected 1.","messagePattern":"Read (.+?) bytes, expected 1\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"testassets/TestClient/Scenarios/RawUpgradeScenario.cs","lineNumber":61,"sourceCode":"        for (var i = 0; i <= 255; i++)\n        {\n            buffer[0] = (byte)i;\n            await rawStream.WriteAsync(buffer, cancellation);\n            var read = await rawStream.ReadAsync(buffer, cancellation);\n            if (i == 255)\n            {\n                if (read != 0)\n                {\n                    throw new Exception($\"Read {read} bytes, expected 0 after sending Goodbye.\");\n                }\n\n                Console.WriteLine();\n            }\n            else\n            {\n                if (read != 1)\n                {\n                    throw new Exception($\"Read {read} bytes, expected 1.\");\n                }\n\n                if (buffer[0] != i)\n                {\n                    throw new Exception($\"Received {buffer[0]}, expected {i}.\");\n                }\n\n                Console.Write(\".\");\n            }\n        }\n\n        Console.WriteLine($\"256 ping/pong's completed in {stopwatch.ElapsedMilliseconds} ms.\");\n    }\n}\n","sourceCodeStart":43,"sourceCodeEnd":76,"githubUrl":"https://github.com/dotnet/yarp/blob/bd11867bee7df522e7fd3effb08a9c85fd616908/testassets/TestClient/Scenarios/RawUpgradeScenario.cs#L43-L76","documentation":"Asserted inside RawUpgradeScenario's echo loop for every byte except the final goodbye (i == 255). After writing one byte it expects exactly one byte echoed back; if ReadAsync returns a count other than 1 it throws Exception with the actual count, indicating the upgraded stream is not doing a clean one-byte echo.","triggerScenarios":"Running RawUpgradeScenario against a raw-upgrade endpoint that buffers, fragments, or drops bytes rather than echoing exactly one byte per write.","commonSituations":"Backend that echoes in chunks; a proxy in front that coalesces or splits frames; TCP-level buffering returning 0 (closed) mid-loop; the stream returning more than one byte because the backend sent ahead.","solutions":["Use the matching test backend that performs a strict one-byte echo.","Ensure no intermediary (proxy, TLS terminator) alters the upgraded byte stream.","If you control the backend, echo exactly the bytes received per read.","Inspect where in the 0..255 range the failure occurs (printed dots show progress) to spot partial connectivity."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await RawUpgradeScenario.RunAsync(client, args, cancellation); }\ncatch (Exception ex) when (ex.Message.Contains(\"expected 1\")) {\n    Console.Error.WriteLine(\"Upgraded stream did not echo one byte per write; check backend and intermediaries.\");\n    return 1;\n}","preventionTips":["Use the strict one-byte echo backend the scenario expects.","Remove intermediaries that coalesce or fragment the upgraded stream.","Watch the printed dots to see how far the loop got before failing."],"tags":["test","http-upgrade","scenario","test-client","yarp"],"backgroundTag":null,"analyzedSha":"bd11867bee7df522e7fd3effb08a9c85fd616908","analyzedAt":"2026-08-13T21:29:49.359Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}