Repository navigation
fix(pnpr): cap distinct interned configs to bound resolver memory - #12674
Conversation
The resolve and verify-lockfile endpoints intern one `&'static Config` per distinct client configuration, keyed by the canonical JSON of the caller-supplied `registry`, `namedRegistries`, `overrides`, and verification policy. Each config is leaked because pacquet's install path requires a `&'static Config`, and the cache was unbounded. An authenticated caller could therefore exhaust the server's memory by sending a request with a fresh registry/policy combination every time: each distinct key leaks another config that can never be reclaimed. The field's "typically one" rationale only holds for honest clients. Cap the cache at MAX_INTERNED_CONFIGS (1024, matching MAX_RESOLUTION_CACHE_ENTRIES); past the cap, both endpoints return 503 instead of interning more. Eviction is not an option here — a leaked config can't be freed, and removing its key would just let the same key be re-leaked, so refusing to leak past a hard cap is the only real bound. Reclaiming memory instead would require threading `Arc<Config>` through pacquet's install path in place of `&'static Config`, which is out of scope for this fix. The cap is far above the handful of distinct setups a real fleet produces, and it resets on restart, so legitimate callers never hit it. Co-authored-by: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe resolver now bounds config interning, preserves existing cached configs, and returns HTTP 503 when config creation is unavailable. Unit tests cover the cap, byte limit, and override canonicalization. ChangesResolver config interning cap
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested labels
Suggested reviewers
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoCap pnpr interned resolver configs to prevent unbounded leaked memory Description
Diagram
High-Level Assessment
Files changed (2)
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpr/crates/pnpr/src/resolver/tests.rs`:
- Around line 235-241: The test in tests::intern_config currently only checks
that the over-cap insert returns None, which does not prove nothing was cached.
Update this regression test around intern_config and configs to also assert the
cache size remains exactly max after the rejected
registry_request("https://c.test/") attempt, so the observable behavior is that
no additional interning happens beyond the limit.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 6ededd78-62b9-4088-8412-c08e7ecda10f
📒 Files selected for processing (2)
pnpr/crates/pnpr/src/resolver.rspnpr/crates/pnpr/src/resolver/tests.rs
Code Review by Qodo
1.
|
|
Code review by qodo was updated up to the latest commit c633408 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #12674 +/- ##
==========================================
- Coverage 87.48% 87.03% -0.46%
==========================================
Files 370 375 +5
Lines 55767 57881 +2114
==========================================
+ Hits 48789 50374 +1585
- Misses 6978 7507 +529 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.839235714199999,
"stddev": 0.12779093163861416,
"median": 4.819434100900001,
"user": 4.10266666,
"system": 3.449539159999999,
"min": 4.6588721494,
"max": 5.1002692254,
"times": [
4.8183992744,
5.0006146914,
4.7425105294,
5.1002692254,
4.7945996774,
4.8361615414,
4.8669556954,
4.8204689274,
4.7535054304,
4.6588721494
]
},
{
"command": "pacquet@main",
"mean": 4.8517240629,
"stddev": 0.110817412165757,
"median": 4.8220279394,
"user": 4.081259859999999,
"system": 3.455724859999999,
"min": 4.6997824374,
"max": 5.0605636014,
"times": [
5.0605636014,
4.7998644134,
4.8619463064,
5.0084634444,
4.8930720324,
4.7566934764,
4.6997824374,
4.8376289484,
4.8064269304,
4.7927990384
]
},
{
"command": "pnpr@HEAD",
"mean": 2.9899708112,
"stddev": 0.16388538167347738,
"median": 2.9626949303999996,
"user": 2.7920416599999998,
"system": 2.955517659999999,
"min": 2.8212739684,
"max": 3.2650366604,
"times": [
2.9126043243999997,
2.8212739684,
3.2650366604,
3.0127855364,
2.8821980534,
2.8254335484,
3.0404084863999996,
3.2373448754,
3.0646368734,
2.8379857854
]
},
{
"command": "pnpr@main",
"mean": 2.9748584372999995,
"stddev": 0.07248176483572895,
"median": 2.9724902934,
"user": 2.83531566,
"system": 2.9602276599999993,
"min": 2.8686812624,
"max": 3.0924082484,
"times": [
3.0924082484,
2.9783688074,
2.8760539923999997,
2.9222441094,
2.9640259654,
2.9973833004,
3.0343749663999997,
3.0484319413999996,
2.8686812624,
2.9666117794
]
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.6408853062800002,
"stddev": 0.011159450946264672,
"median": 0.6389189951800001,
"user": 0.38331824000000003,
"system": 1.32461924,
"min": 0.6263112661800001,
"max": 0.65412259518,
"times": [
0.6312113871800001,
0.6331970041800001,
0.65412259518,
0.6523415321800001,
0.6322560131800001,
0.6263112661800001,
0.6511182341800001,
0.6446409861800001,
0.6305537011800001,
0.6531003431800001
]
},
{
"command": "pacquet@main",
"mean": 0.6597524961800001,
"stddev": 0.02536665189157406,
"median": 0.6538014226800001,
"user": 0.38079493999999997,
"system": 1.33312914,
"min": 0.6400946501800001,
"max": 0.7282636651800001,
"times": [
0.6647950361800001,
0.6421818261800001,
0.6544977741800001,
0.6531818971800001,
0.6635332591800001,
0.6400946501800001,
0.7282636651800001,
0.64830683318,
0.64824907218,
0.6544209481800001
]
},
{
"command": "pnpr@HEAD",
"mean": 0.7007699564800001,
"stddev": 0.014983128788863797,
"median": 0.69720323118,
"user": 0.39006864,
"system": 1.37546714,
"min": 0.6818070771800001,
"max": 0.7319752481800001,
"times": [
0.7151952931800001,
0.68908262218,
0.6912115261800001,
0.7039946111800001,
0.6900275011800001,
0.6818070771800001,
0.7099992231800001,
0.6944997671800001,
0.7319752481800001,
0.6999066951800001
]
},
{
"command": "pnpr@main",
"mean": 0.71042218908,
"stddev": 0.024778266855226203,
"median": 0.7093485136800001,
"user": 0.4069711399999999,
"system": 1.3533307399999999,
"min": 0.6840753801800001,
"max": 0.76271667218,
"times": [
0.6840753801800001,
0.7245227441800001,
0.6992813091800001,
0.6867506451800001,
0.6956746021800001,
0.7209538991800001,
0.76271667218,
0.7248330031800001,
0.6859979171800001,
0.71941571818
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.835787938039999,
"stddev": 0.04883978443168009,
"median": 4.82718788634,
"user": 3.9518643199999994,
"system": 3.3827250199999996,
"min": 4.77581217234,
"max": 4.94414730234,
"times": [
4.80931922934,
4.84570142734,
4.82714290834,
4.82657791834,
4.87463239534,
4.94414730234,
4.82723286434,
4.77753892134,
4.84977424134,
4.77581217234
]
},
{
"command": "pacquet@main",
"mean": 4.84301251724,
"stddev": 0.06367353260059201,
"median": 4.83972467084,
"user": 3.9472220200000003,
"system": 3.37494322,
"min": 4.75024920934,
"max": 4.94231123734,
"times": [
4.84891498234,
4.79083809334,
4.79545155634,
4.79086397134,
4.83053435934,
4.75024920934,
4.905622560339999,
4.85434660634,
4.92099259634,
4.94231123734
]
},
{
"command": "pnpr@HEAD",
"mean": 3.29724497694,
"stddev": 0.15836716896829206,
"median": 3.28387122884,
"user": 2.9340741200000005,
"system": 3.14588922,
"min": 3.0799753543399997,
"max": 3.59699341434,
"times": [
3.21550927734,
3.41833262234,
3.46139497434,
3.1836974743399997,
3.59699341434,
3.1335894243399998,
3.28713160734,
3.31521477034,
3.0799753543399997,
3.28061085034
]
},
{
"command": "pnpr@main",
"mean": 3.2335115471399996,
"stddev": 0.09706733491550583,
"median": 3.21861953634,
"user": 2.89881562,
"system": 3.15637962,
"min": 3.0906185533399997,
"max": 3.42457396334,
"times": [
3.2013837073399998,
3.23585536534,
3.3244988743399997,
3.42457396334,
3.2791265673399996,
3.18980856934,
3.27219192434,
3.1283019733399997,
3.0906185533399997,
3.1887559733399997
]
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.3948259978000002,
"stddev": 0.01688959338105943,
"median": 1.3944935266000003,
"user": 1.36520518,
"system": 1.6982741000000001,
"min": 1.3726574971,
"max": 1.4346257791,
"times": [
1.3942354841000002,
1.3976723101000001,
1.4010450471,
1.3788169641,
1.3726574971,
1.3852415411,
1.4015524301000002,
1.4346257791,
1.3947515691,
1.3876613561000002
]
},
{
"command": "pacquet@main",
"mean": 1.4189992404000003,
"stddev": 0.027284488594587913,
"median": 1.4153744041,
"user": 1.36389248,
"system": 1.7398401999999997,
"min": 1.3877113991,
"max": 1.4893061501000002,
"times": [
1.4180027851,
1.3974585341,
1.4893061501000002,
1.3877113991,
1.4063625911000002,
1.4132944101,
1.4237277031000002,
1.4174543981,
1.4114396481000002,
1.4252347851
]
},
{
"command": "pnpr@HEAD",
"mean": 1.4640731049000002,
"stddev": 0.028485955975090047,
"median": 1.4558254916000002,
"user": 0.5769922799999999,
"system": 1.574755,
"min": 1.4221162011000001,
"max": 1.5017112361,
"times": [
1.4984260451000002,
1.4936216091,
1.5017112361,
1.4353676681000003,
1.4558326311,
1.4855718491,
1.4442835081,
1.4221162011000001,
1.4479819491,
1.4558183521
]
},
{
"command": "pnpr@main",
"mean": 1.4838686166000001,
"stddev": 0.02146091028950815,
"median": 1.4770668671,
"user": 0.5881972799999999,
"system": 1.5981276999999996,
"min": 1.4584151761000002,
"max": 1.5314117941,
"times": [
1.5314117941,
1.4683991191,
1.4715023711000002,
1.5068945991,
1.4750599071000001,
1.4911302111000002,
1.4790738271000001,
1.4712811331000002,
1.4584151761000002,
1.4855180281000002
]
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.13687027418,
"stddev": 0.07505496148483844,
"median": 3.11716794288,
"user": 1.8429788999999999,
"system": 1.9899844999999998,
"min": 3.06170437088,
"max": 3.27247949088,
"times": [
3.15012980788,
3.06170437088,
3.11726903688,
3.0915424148799997,
3.06280947688,
3.09005456688,
3.11706684888,
3.26314046788,
3.1425062598799998,
3.27247949088
]
},
{
"command": "pacquet@main",
"mean": 3.1118503221799996,
"stddev": 0.02849557812869541,
"median": 3.10807461288,
"user": 1.843198,
"system": 1.9942737000000001,
"min": 3.0806677158799998,
"max": 3.15711915588,
"times": [
3.09850476488,
3.15711915588,
3.0806677158799998,
3.11991056788,
3.11764446088,
3.09825844488,
3.0820327338799998,
3.08160637288,
3.12960565688,
3.15315334788
]
},
{
"command": "pnpr@HEAD",
"mean": 1.50237996638,
"stddev": 0.016824720620197745,
"median": 1.4972760453799998,
"user": 0.6031317,
"system": 1.6113203999999997,
"min": 1.47449087688,
"max": 1.5286607348799999,
"times": [
1.5185655598799999,
1.49640721488,
1.5286607348799999,
1.4975545928799998,
1.5257577488799998,
1.49895475488,
1.4969974978799998,
1.47449087688,
1.49435821588,
1.49205246688
]
},
{
"command": "pnpr@main",
"mean": 1.50572480658,
"stddev": 0.024230926515987943,
"median": 1.51383726588,
"user": 0.5944629,
"system": 1.6014764,
"min": 1.4533776758799999,
"max": 1.53521752288,
"times": [
1.49993799788,
1.51850428588,
1.49413307588,
1.5124187118799999,
1.5296602988799999,
1.5160107168799999,
1.53521752288,
1.51525581988,
1.48273195988,
1.4533776758799999
]
}
]
} |
|
| Branch | pr/12674 |
| Testbed | pacquet |
Click to view all benchmark results
| Benchmark | Latency | Benchmark Result milliseconds (ms) (Result Δ%) | Upper Boundary milliseconds (ms) (Limit %) |
|---|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,835.79 ms(+1.65%)Baseline: 4,757.14 ms | 5,708.57 ms (84.71%) |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot 🚷 view threshold | 3,136.87 ms(+3.12%)Baseline: 3,041.97 ms | 3,650.36 ms (85.93%) |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 1,394.83 ms(+2.83%)Baseline: 1,356.45 ms | 1,627.74 ms (85.69%) |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot 🚷 view threshold | 4,839.24 ms(+1.20%)Baseline: 4,782.09 ms | 5,738.51 ms (84.33%) |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot 🚷 view threshold | 640.89 ms(-2.37%)Baseline: 656.45 ms | 787.74 ms (81.36%) |
|
| Branch | pr/12674 |
| Testbed | pnpr |
⚠️ WARNING: No Threshold found!Without a Threshold, no Alerts will ever be generated.
Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the--ci-only-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 3,297.24 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 1,502.38 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 1,464.07 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 2,989.97 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 700.77 ms |
Addresses the review on this PR: - Cap each interned config's canonical-key size (MAX_CONFIG_KEY_BYTES, 128 KiB), not just the count. The resolve/verify body inherits the publish-sized DefaultBodyLimit, so a caller could pad a distinct config's overrides/namedRegistries map and amplify the per-config leak even under the count cap; refuse to intern an oversized key. - Assert the cache size stays exactly at the cap after an over-cap request is refused, proving the refusal interns nothing. - Rewrite the cap-test assertions as single-line calls via a closure, fixing the `perfectionist::macro-trailing-comma` dylint error that failed Rust CI. Co-authored-by: Claude <[email protected]>
There was a problem hiding this comment.
♻️ Duplicate comments (1)
pnpr/crates/pnpr/src/resolver/tests.rs (1)
260-265: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick winAssert the oversized config was not interned.
is_none()alone does not prove the oversized request left the cache unchanged. A buggy path could still insert/leak the config and returnNone, and this test would pass.Suggested assertion
// A configuration whose canonical key exceeds the byte cap is refused, so a // caller can't amplify the per-config leak with a giant overrides/registry. let oversized = format!("https://{}.test/", "x".repeat(2048)); assert!(intern(&oversized).is_none()); + assert_eq!(configs.lock().expect("config cache poisoned").len(), 1);As per path instructions,
REVIEW_GUIDE.mdsays regression tests should avoid vacuous assertions and specifically cover that refused requests do not increase cache.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpr/crates/pnpr/src/resolver/tests.rs` around lines 260 - 265, The oversized-config test for intern is currently vacuous because is_none() does not prove the refused request left the cache unchanged. Update the test around intern("https://a.test/") and the oversized request to also assert that the rejected oversized key was not added to the intern cache, preferably by checking the cache size or count before and after the oversized call using the relevant intern/cache accessors in resolver/tests.rs. Keep the existing is_none() check, but add a concrete assertion that no new entry was interned for the oversized config.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Duplicate comments:
In `@pnpr/crates/pnpr/src/resolver/tests.rs`:
- Around line 260-265: The oversized-config test for intern is currently vacuous
because is_none() does not prove the refused request left the cache unchanged.
Update the test around intern("https://a.test/") and the oversized request to
also assert that the rejected oversized key was not added to the intern cache,
preferably by checking the cache size or count before and after the oversized
call using the relevant intern/cache accessors in resolver/tests.rs. Keep the
existing is_none() check, but add a concrete assertion that no new entry was
interned for the oversized config.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: be5abf29-01a1-4afd-9b50-d826639b62cb
📒 Files selected for processing (2)
pnpr/crates/pnpr/src/resolver.rspnpr/crates/pnpr/src/resolver/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- pnpr/crates/pnpr/src/resolver.rs
|
Code review by qodo was updated up to the latest commit f5fe50c |
1 similar comment
|
Code review by qodo was updated up to the latest commit f5fe50c |
Addresses a follow-up review on this PR: the cache key is documented as canonical JSON, but `overrides` was deserialized into an insertion-ordered `IndexMap` and serde_json runs with `preserve_order`, so the same overrides sent with a different key order produced distinct keys — interning duplicate leaked configs, defeating dedup and burning through MAX_INTERNED_CONFIGS faster. Build the key's `overrides` from a sorted `BTreeMap` so reordered duplicates collapse to one config. The stored config keeps the request's `IndexMap` (order doesn't affect resolution). Co-authored-by: Claude <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@pnpr/crates/pnpr/src/resolver/tests.rs`:
- Around line 284-286: The test in intern should verify actual config reuse, not
just cache size. Capture the results of both intern(...) calls in this test and
assert they point to the same PacquetConfig instance using pointer/reference
equality, in addition to the existing cache len check. This will ensure the
dedup behavior in intern and the config cache behind configs.lock() is truly
reusing the interned config rather than silently creating a second one.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: e1cc7eb2-1277-429a-80bf-d11134fae7bf
📒 Files selected for processing (2)
pnpr/crates/pnpr/src/resolver.rspnpr/crates/pnpr/src/resolver/tests.rs
🚧 Files skipped from review as they are similar to previous changes (1)
- pnpr/crates/pnpr/src/resolver.rs
|
Code review by qodo was updated up to the latest commit a08d929 |
Follow-up review on this PR: `len() == 1` only proves the key deduped — a buggy impl could leak a second config and still leave the map at one entry. Capture both returned refs and assert `std::ptr::eq` so the test proves the second call reuses the same leaked `&'static Config`. Co-authored-by: Claude <[email protected]>
|
Code review by qodo was updated up to the latest commit a08d929 |
|
Code review by qodo was updated up to the latest commit 55dd395 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 55dd395 |
Summary
The pnpr resolver interns one
&'static Configper distinct clientconfiguration — keyed by the canonical JSON of the caller-supplied
registry,namedRegistries,overrides, and verification policy — andthis cache was unbounded. Each config is leaked (
config.leak())because pacquet's install path requires a
&'static Config.An authenticated caller of
POST /-/pnpr/v0/resolve(or/-/pnpr/v0/verify-lockfile) can therefore exhaust the server's memory bysending a fresh registry/policy combination on every request: each
distinct key leaks another
Configthat can never be reclaimed. Thefield's "typically one distinct config" rationale only holds for honest
clients.
This caps the cache at
MAX_INTERNED_CONFIGS(1024, matching theexisting
MAX_RESOLUTION_CACHE_ENTRIES). Past the cap, both endpointsreturn
503instead of interning more. The interning logic is extractedinto a free
intern_configfunction so the bound is unit-testablewithout standing up a whole
Resolver.Why a hard cap and not LRU eviction: a leaked config can't be freed, and
removing its key from the map would just let the same key be re-leaked on
the next request — so refusing to leak past a fixed cap is the only real
bound. Reclaiming memory instead would mean threading
Arc<Config>through pacquet's install path in place of
&'static Config, which is outof scope here. The cap is far above the handful of distinct setups a real
fleet produces, and it resets on restart, so legitimate callers never hit
it.
Squash Commit Body
Checklist
configsfield).Written by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit