Skip to main content

MAX_RECURSIVE_NESTING

Constant MAX_RECURSIVE_NESTING 

Source
pub const MAX_RECURSIVE_NESTING: u32 = 256;
Expand description

#2656: the most levels of recursive-type nesting a boundary codec accepts. A value of a recursive type is one level; each value of a recursive type nested inside it, through any fields, variants or containers, is one more. A value of a non-recursive type is not counted and, as its codec carries no depth, the count starts again below it; such a type occurs a fixed number of times on any path, so the total stays bounded. Decoding a value nested deeper is a StructuralMismatch at the path where the bound is crossed; encoding one throws, as a non-finite Float does.

Measured on Node 22 against the emitted workers codecs before the bound existed (cold code, one fresh process per probe), the shallowest overflow of the four reference shapes was a record recursing through a Map, at 1,394 levels when decoding. The bound is a quarter of that or less, because the Workers runtime’s stack can be smaller than Node’s, and no less than 256, so that legitimately deep data (a long linked list) still crosses. The measurements are recorded in the ADR for #2656, and the bound in the specification (§6.5); changing it changes which values cross a boundary.