Skip to content

A method cannot state its largest request, so an RPC route passes a body of any size to its service #80

Done

Description

@tudor-pop

An RPC route passes a request body of any size to its service: neither a methods file nor a method's .proto option
can say how large a method's request may be, so a service that accepts large messages for one method reads a message
of that size for every method behind the gateway. Envoy's buffer filter can refuse a larger body per route, before
the service reads any of it, but proxyfile writes no such limit.

What changes:

  • A method may carry max_request_bytes: the largest request message, in bytes as serialized, the route passes on.
    It is read from a methods file (rpc.methods[].max_request_bytes, an integer from 1 to 4,294,967,290) and, under
    rpc.proto, from a field of that name in the option's message, which must hold one uint32 when the message has
    it (as reports is read today; any other field stays untouched).
  • The RPC table writes "max_request_bytes": N on the rows of the methods that carry one, and nothing on the others.
  • The Envoy output lists envoy.filters.http.buffer once, disabled, right before the Connect bridge (before the
    router without one), with the smallest route's value, and turns it on for each limited method's route with
    BufferPerRoute N + 5 (the gRPC prefix). Measured on Envoy 1.40.2: a message of exactly N passes in Connect and in
    gRPC over HTTP/1.1, and N + 1 is refused, with 413 text/plain Payload Too Large to a Connect call and
    grpc-status 2 with that message to a gRPC call.
  • The buffer filter counts the bytes it receives, so it cannot bound what a compressed message inflates to: gzip
    writes 128 MiB of zeros in about 130,500 bytes, under a limit of 131,072. Right before each limited method's route,
    the Envoy output therefore writes two routes on the same path that answer 415 to a request whose grpc-encoding or
    content-encoding is present and not identity (measured on Envoy 1.40.2: a Connect call gets 415, a gRPC call
    grpc-status 2, and the backend sees neither).
  • nginx and HAProxy refuse the key in this version, as ask_unlisted is refused: "not written by this version's
    nginx generator; leave max_request_bytes out, or render it for envoy" (and the HAProxy form). A file without the key
    renders byte for byte as 2.3.1 does, for every target.
  • Tests: the RPC table with and without the key; the option field read, absent and of the wrong type; the refusal by
    nginx and HAProxy through a methods file and through rpc.proto; the full example before the key rendered byte for
    byte as 2.3.1; the filter entry, the per-route value and the two 415 routes; a conformance scenario on Envoy (exactly
    N passes, N + 1 refused in each form, compressed refused, the stub backend sees only the passing call); the core key
    count from 131 to 132.
  • Docs: docs/rpc.md, docs/limits.md, docs/portability.md, a "After 2.3.1" section in docs/format.md, and the
    release named in README.md and docs/editors.md, which still say v2.2.0. Released as v2.4.0.

Consumers

  • Every existing Proxyfile and every file it writes: with the key absent the Envoy, nginx and HAProxy outputs and the
    RPC table are byte-identical to 2.3.1's, proven by a golden of the full example before the key and by the examples
    check (go test -count=1 ./... 2>&1 | grep -E '^(ok|FAIL)').
  • A reader of the RPC table that refuses unknown keys must accept max_request_bytes before it reads a table written
    from a file that uses the key; a table from a file without it is unchanged.
  • The JSON schema (schema/proxyfile.schema.json) and the key tables of the README and docs, rewritten by
    go test ./internal/format -run TestSchemaIsCurrent -update; examples/full, the files that write every key, use it.
  • An option message that already has a field named max_request_bytes of another type: refused with a problem at the
    option, where 2.3.1 left it alone; noted in "After 2.3.1".

Open tickets checked: the names max_request, request body, buffer filter, request size and largest request over this repository's open issues found none (2 issues open, #74 and #77, both about other things).

Lane

FULL: it changes the file format's schema and the RPC table other programs read, and decides which requests a route
refuses before its service.

Scope update (3 December 2026)

A review of the design found two request forms the routes described above do not cover:

  • A Connect GET carries its message in the query string. Envoy's buffer filter does nothing for a request without a body, so the limit does not apply to it, and a compression parameter is not a request header.
  • A request in the Connect streaming form names its compression in connect-content-encoding.

So the Envoy output for a method with max_request_bytes also writes, before the method's route: one route that answers 405 to a GET (a method with a limit takes its message in a request body only), and a third 415 route for connect-content-encoding. A file without the key still renders as 2.3.1 does.

Added to the acceptance: tests for the route order and the two new routes, conformance rows for a Connect GET (405) and a compressed streaming-form request (415), and the docs say that over HTTP/2 a body that arrives whole in one frame is not counted by Envoy's buffer filter.

Scope update (3 December 2026): a request with a query string

A probe of the output found one more request form the routes above do not cover. Envoy's Connect bridge builds a message from the query string of any request that ends with its headers, whatever its method, and the buffer filter does not count a request without a body. So a POST, PUT or DELETE with no body and a message in its query is not held to the method's limit.

The Envoy output for a method with max_request_bytes therefore writes one more route, right after the GET route: a request whose :path carries a query string is answered 400. A gRPC or Connect call with a body carries no query, so the rule changes nothing for them. The order before the method's route is: 405 on GET, 400 on a query string, then the three 415 routes. A file without the key still renders as 2.3.1 does.

Added to the acceptance: a test for the new route and its place in the order, conformance rows for a POST and a DELETE with no body in the Connect query form (400, nothing sent to the service), and the docs say that a method with a limit takes its message in a request body only.

Activity

  1. added
    enhancement
    on Dec 3, 2026
  2. tudor-pop commented on Dec 3, 2026

    @tudor-pop
    ContributorAuthor

    Review of the branch before its pull request

    One independent review in two parts on the pushed branch, one round of corrections built tests first, then a second pass by the second reviewer at the corrected code. Example names as in the docs (shop.v1.CartService/AddItem, a limit of 2,048 bytes).

    Part 1: the code and the tests

    One important point, three minor ones and three notes.

    • Important: the five refusal routes were not counted by the rpc entry's rate limit. The routes that answer 405, 400 and 415 before a limited method's own route carried no rate-limit entry, so a request they refuse took no token from the entry's bucket, where the same request took one before the limit existed. Corrected: the five routes carry the method route's metadata and its question for the auth check, built from two shared fragments so a later key of the method's route cannot be forgotten on them. A refused request is now counted and asked about as the method's own call would be; only the answer differs.
    • Minor: docs/rpc.md stated the limit without the HTTP/2 one-frame exception; no test rendered the refusal routes of a limited method without the Connect bridge; one test comment named a limit its rows do not use. All three corrected.
    • Notes taken: a declared default of the option's field is a limit on every method (now said in docs/rpc.md), and two small code comments.

    Part 2: request forms sent to a local Envoy 1.40.2

    185 request forms, with a stub behind the proxy and, for the compressed forms, a real gRPC server. Three important points and three minor ones.

    • Important: a compression header written twice, once as identity, was not refused. The first form of the rule was an inverted exact match, and Envoy 1.40.2 matches each value of a repeated header on its own, so a request with grpc-encoding: identity and grpc-encoding: gzip on two lines went on to the method's route, and the server behind it inflated the message past the limit. Corrected: one regular expression per header that matches any value other than identity, with no inverted match. It answers the same whether the values arrive on separate lines or joined.
    • Important: the docs said the limit is exact, and for a body without a frame prefix it is not. The route's value is the limit and the 5 bytes of the gRPC prefix. A Connect unary call the bridge does not convert (one sent without connect-protocol-version), or any Connect unary call in a file without the bridge, carries no prefix, so a body of up to the limit and 5 bytes reaches the service. This is not refused; docs/limits.md now states it, and two conformance rows hold it (the limit and 5 bytes: served; the limit and 6 bytes: 413).
    • Important: a route written before the rpc entry could take a limited method's path, and the file rendered without a word. That method's limit then never applied. Corrected: such a file is refused, for a prefix, a path or a pattern, whatever the route's other conditions: route "cart" is written before the rpc entry and takes the path of shop.v1.CartService/AddItem, so that method's max_request_bytes would not apply; write the route after the rpc entry.
    • Decided with these: a method that takes a stream of requests cannot set the limit, because the buffer filter holds a request until it ends. With rpc.proto, such a method that sets the field is refused.
    • Minor, all three now in docs/limits.md: a Connect body 1 to 5 bytes over the limit may be seen by the service as a call opened and reset, with no byte of the message; "any compressed request" was wider than what the routes refuse (they refuse a request that names a compression other than identity); a gRPC-Web text body is base64, so its message is at most about three quarters of the limit.

    The second pass, at the corrected code

    No important finding.

    • All 21 repeated and list forms of the three headers are refused, and the real server inflated none (4 in the first pass). A single identity and no header at all are served.
    • Each refused form took a token from the rpc entry's bucket and asked the check with the method's action. Past the bucket the answer is 429 (grpc-status 8 for a gRPC call) with no check call. An action a caller wrote into its own request reached the check in 0 of 7 calls.
    • No way around the refusal of a route before the rpc entry was found: a prefix route, five kinds of pattern, a route with method: GET, a rewrite, auth: off, an include, a concatenation and two rpc entries were each refused.
    • Of the 184 forms sent again, 20 answered differently: 9 are the new refusals, and 11 differ only in whether the stub saw a call opened with no byte of the message, which varies from run to run.
    • Forms that still pass a message over the limit to the method's path: 12, each one a case docs/limits.md states (4 without a frame prefix over HTTP/1.1, up to 5 bytes over; 8 over HTTP/2 in one frame).
    • One minor point and two notes, all doc sentences, corrected in the branch's last commit: the short rule in docs/rpc.md read as if the frame-prefix case were an HTTP/2 matter; docs/rpc.md did not say a gRPC call gets the refusal as grpc-status 2; and a call opened and reset with no byte of the message also happens over HTTP/2.

    Not verified by the review: the proxy's peak memory under many held requests, and a live server-streaming call through a limited method.

  3. tudor-pop commented on Dec 3, 2026

    @tudor-pop
    ContributorAuthor

    Shipped in release v2.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions