Skip to content

Lift the traversal limit on Rust JSG feature flags - #8159

Merged
nathanwhit merged 1 commit into
mainfrom
nathanwhit/feature-flags-traversal-limit
Nov 3, 2026
Merged

nathanwhit merged 1 commit into
mainfrom
nathanwhit/feature-flags-traversal-limit

Conversation

@nathanwhit

Copy link
Copy Markdown
Member

Each isolate's Realm holds a single capnp Reader over the canonical compatibility-flags message, and every Lock::feature_flags() call reads the root struct through it. A Reader charges each read against a traversal limit (8M words by default) and never resets the count. After about a million reads in one isolate, every later read fails. FeatureFlags::reader() then panics, and the JavaScript caller gets an internal error. The isolate stays in this state until it is torn down.

Since fd0a66d (first released in v1.20261028.1), converting a #[jsg_struct] to JavaScript reads fast_jsg_struct, so every Rust method that returns a struct draws on this budget. In production today that means only node-internal:dns (parseCaaRecord / parseNaptrRecord, used by node:dns resolveCaa / resolveNaptr). Each call follows a DoH subrequest, so reaching the limit in one isolate is unlikely but possible for a busy, long-lived isolate. Hot-path Rust APIs would hit it quickly. A benchmark of the autogated Rust TextEncoder.encodeInto() found the bug.

The traversal limit protects against untrusted messages. These bytes are C++'s own capnp::canonicalize() output, so this change reads them with no limit.

Testing: added reader_has_no_traversal_limit, which reads the flags twice as many times as the default limit allows.

FeatureFlags keeps one capnp message Reader for the life of its Realm,
and every Lock::feature_flags() call reads the root struct through it.
A Reader charges each read against a traversal limit (8M words by
default) that it never resets, so after about a million reads in one
isolate every further read failed and FeatureFlags::reader() panicked,
which a JavaScript caller sees as an internal error.

A #[jsg_struct]'s conversion to JavaScript reads the fast_jsg_struct
flag, so a Rust method returning a struct hit the limit after about a
million calls. A benchmark of a Rust TextEncoder.encodeInto(), which
returns one, found it.

The limit guards against untrusted messages. These bytes are C++'s own
capnp::canonicalize() output, so read them without one.
@nathanwhit
nathanwhit requested review from a team as code owners November 2, 2026 20:11

@clanky-the-clanker clanky-the-clanker Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved — This is a small, well-scoped fix with a regression test that covers the exhausted traversal budget; I found no issues.

The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.


✅ All checks passed

📋 Code Quality: ✅ LGTM

The ReaderOptions change is correct for trusted, self-produced canonical bytes. The regression test reads more times than the default limit allows.


📝 Documentation: ✅ LGTM

The new code and test comments describe the current behaviour, as the repository's comment guidelines ask.


Reviewed commit: debced75

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 68.34%. Comparing base (8c73a6e) to head (debced7).
⚠️ Report is 116 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8159      +/-   ##
==========================================
- Coverage   68.48%   68.34%   -0.15%     
==========================================
  Files         721      726       +5     
  Lines      186662   189926    +3264     
  Branches    29364    29738     +374     
==========================================
+ Hits       127841   129796    +1955     
- Misses      41654    42705    +1051     
- Partials    17167    17425     +258     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nathanwhit
nathanwhit enabled auto-merge November 2, 2026 23:32
@nathanwhit
nathanwhit merged commit fef2309 into main Nov 3, 2026
50 of 54 checks passed
@nathanwhit
nathanwhit deleted the nathanwhit/feature-flags-traversal-limit branch November 3, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants