dotnet/yarp · error · Exception

Received {buffer[0]}, expected {i}.

Error message

Received {buffer[0]}, expected {i}.

What it means

Asserted inside RawUpgradeScenario's echo loop when a byte was read but its value does not match the byte that was just sent (i). The upgraded stream is expected to echo verbatim; a mismatch means the data path corrupted, reordered, or substituted bytes.

Source

Thrown at testassets/TestClient/Scenarios/RawUpgradeScenario.cs:66

            if (i == 255)
            {
                if (read != 0)
                {
                    throw new Exception($"Read {read} bytes, expected 0 after sending Goodbye.");
                }

                Console.WriteLine();
            }
            else
            {
                if (read != 1)
                {
                    throw new Exception($"Read {read} bytes, expected 1.");
                }

                if (buffer[0] != i)
                {
                    throw new Exception($"Received {buffer[0]}, expected {i}.");
                }

                Console.Write(".");
            }
        }

        Console.WriteLine($"256 ping/pong's completed in {stopwatch.ElapsedMilliseconds} ms.");
    }
}

View on GitHub (pinned to bd11867bee)

Solutions

  1. Use the matching test backend that echoes the exact byte received.
  2. Ensure the send and receive buffers are distinct (the scenario uses a single 1-byte buffer, which is safe, but a custom variant must not alias).
  3. Remove any transforming intermediary (compression, encoding conversion) from the upgraded path.
  4. Inspect the printed expected vs received values to detect off-by-one or constant-byte patterns.
Defensive patterns

Strategy: try-catch

Try / catch

try { await RawUpgradeScenario.RunAsync(client, args, cancellation); }
catch (Exception ex) when (ex.Message.Contains("expected")) {
    Console.Error.WriteLine("Echo byte mismatch on upgraded stream; backend corrupted/reordered data.");
    return 1;
}

Prevention

When it happens

Trigger: Running RawUpgradeScenario against a backend (or through a proxy) that does not echo the exact byte written, e.g. it echoes a previous byte, a constant, or garbage.

Common situations: A buggy echo backend; an intermediary that transforms the payload; buffer aliasing where the sent and received buffers overlap; the stream returning stale data from a previous read.

Related errors


AI-assisted analysis of dotnet/yarp@bd11867bee (2026-08-13). Data as JSON: /api/errors/3c0d89e9e57ab7ff. Report an issue: GitHub.