Repository navigation
Lift the traversal limit on Rust JSG feature flags - #8159
Conversation
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.
There was a problem hiding this comment.
✅ 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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Each isolate's
Realmholds a single capnpReaderover the canonical compatibility-flags message, and everyLock::feature_flags()call reads the root struct through it. AReadercharges 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 readsfast_jsg_struct, so every Rust method that returns a struct draws on this budget. In production today that means onlynode-internal:dns(parseCaaRecord/parseNaptrRecord, used bynode:dnsresolveCaa/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 RustTextEncoder.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.