1724a175b6
Grpc.Net.Client has no per-call receive limit, so Read/GetMetadata/Browse now go through receive-bounded sibling channels (power-of-two size classes, min 16 KiB, sharing the endpoint channel's handler). An oversized response to a scalar read is refused from its length prefix instead of buffering up to MaxMessageBytes; such a refusal stays a decode refusal (ArgumentException, no failover).
43 lines
3.2 KiB
Markdown
43 lines
3.2 KiB
Markdown
# #963 — transport receive bound follows the projected read's decode limit
|
||
|
||
2026-12-01. Follow-up of #960 (`960-961.md`). Consumer side of gRPC data connections (`GrpcDataConnection`).
|
||
|
||
## Root cause
|
||
|
||
#960 sized each projected read's reservation from the node's declared shape (16 KiB for a fixed-size scalar) and used it
|
||
as the decode limit, so up to 64 reads share the default 1 MiB `MaxPendingBytes`. But the gRPC channel's
|
||
`MaxReceiveMessageSize` was the connection's `MaxMessageBytes` (4 MiB by default) for every call, so Grpc.Net.Client
|
||
accepted and fully buffered any response up to that before `DataProtoMapper.Preflight` refused it at decode. A misbehaving
|
||
origin could make 64 scalar reads briefly hold ~64 × MaxMessageBytes.
|
||
|
||
## Fix
|
||
|
||
Grpc.Net.Client 2.76 has no per-call receive limit (only `GrpcChannelOptions.MaxReceiveMessageSize`; `CallOptions` and the
|
||
method config carry none), so each endpoint `ChannelEntry` lazily creates receive-bounded **sibling channels** that share the
|
||
owning channel's `HttpMessageHandler` (one connection pool; `DisposeHttpClient = false`, the owner still disposes it):
|
||
|
||
- `ReceiveClassBytes(limit, max)` = smallest power of two ≥ the call's decode limit (min 16 KiB), capped at the channel
|
||
maximum. A scalar read's class is exactly its 16 KiB reservation; a fixed-array read's at most 2 × its reservation; a
|
||
whole-cap read uses the owning channel. At most log2(max / 16 KiB) + 1 siblings per endpoint channel.
|
||
- `Read`, `GetMetadata` and `Browse` (the `QueryAsync` calls decoded against `Limits(budget, caps)`) go through
|
||
`BoundedUnaryAsync`. Grpc.Net.Client checks the 5-byte length prefix against the limit **before** renting the payload
|
||
buffer, so nothing of the oversized payload is read.
|
||
- A `ResourceExhausted` from a sibling is rethrown as `ArgumentException("Envelope exceeds receiver limits.")` — the same
|
||
outcome as the decode refusal it pre-empts (no endpoint failover / discovery back-off). A response over the channel
|
||
maximum is unchanged (`RpcException` → endpoint failure).
|
||
|
||
Not covered: `HistoryRead`, `CallConditionMethod` and the write path's metadata call still use the owning channel (they are
|
||
not part of the small-reservation read budget).
|
||
|
||
## Red / green
|
||
|
||
| Test | pre-fix | fix |
|
||
|---|---|---|
|
||
| Runtime.Tests `An_oversized_origin_response_to_a_scalar_read_is_refused_from_its_length_prefix` (1 MiB valid-protobuf response to a 16 KiB read, 4 MiB channel; counts bytes the client pulled from the body) | **FAIL** — 1048581 bytes consumed, then decode refused | pass — ≤ 5 bytes (the length prefix) |
|
||
| `A_normal_scalar_read_and_a_large_string_read_still_succeed` (16 KiB scalar, 20 K-char string at 128 KiB, same string at the channel max) | pass | pass |
|
||
| `A_response_over_the_channel_maximum_keeps_endpoint_failure_handling` (control) | pass | pass |
|
||
| `Receive_class_…` (8 cases) + `A_scalar_reservation_is_its_own_receive_class` | n/a (new API) | pass |
|
||
| Host.IntegrationTests `Receive_bounded_and_channel_maximum_reads_share_one_real_tls_channel` (real Kestrel TLS/HTTP2, 16 K / 64 K / 32 K / 16 K budgets on one connection) | n/a | pass |
|
||
|
||
Pre-fix was reproduced by forcing `BoundedClient` to return the owning client.
|