Add some calls to addTempRoot()#527
Conversation
Based on upstream 0b29401.
📝 WalkthroughWalkthroughThis change adds garbage-collection root protection for store paths in two locations: ChangesTemp-root store paths before validity checks
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
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 `@src/libfetchers/fetchers.cc`:
- Line 381: The fast-path in makeStorePathFromURI still bypasses the
temporary-root protection, so the store can be returned from makeStoreAccessor()
without rooting it. Update the makeStorePathFromURI flow to add the temp root
before the early storePath && store.isValidPath(*storePath) return path, keeping
the protection consistent with the substitution branch and preserving the
existing requireStoreObjectAccessor() / queryPathInfo() behavior.
🪄 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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 63a8f6d0-d9f8-4c20-9aa8-7122e63461ca
📒 Files selected for processing (2)
src/libexpr/eval-cache.ccsrc/libfetchers/fetchers.cc
| /* If not, try to substitute the input. */ | ||
| if (storePath) { | ||
| try { | ||
| store.addTempRoot(*storePath); |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Root storePath before the fast-path validity check too.
Line 381 protects only the substitution branch. The earlier storePath && store.isValidPath(*storePath) fast path can still return through makeStoreAccessor() without a temp root, leaving the same GC race before requireStoreObjectAccessor() / queryPathInfo().
🐛 Proposed fix
std::optional<StorePath> storePath;
if (isFinal() && getNarHash())
storePath = computeStorePath(store);
+ bool storePathTempRooted = false;
+ auto addStorePathTempRoot = [&]() {
+ if (storePath && !storePathTempRooted) {
+ store.addTempRoot(*storePath);
+ storePathTempRooted = true;
+ }
+ };
auto makeStoreAccessor = [&]() -> std::pair<ref<SourceAccessor>, Input> {
auto accessor = store.requireStoreObjectAccessor(*storePath);
@@
- if (storePath && store.isValidPath(*storePath)) {
- debug("using input '%s' in '%s'", to_string(), store.printStorePath(*storePath));
- return makeStoreAccessor();
+ if (storePath) {
+ addStorePathTempRoot();
+ if (store.isValidPath(*storePath)) {
+ debug("using input '%s' in '%s'", to_string(), store.printStorePath(*storePath));
+ return makeStoreAccessor();
+ }
}
@@
if (storePath) {
try {
- store.addTempRoot(*storePath);
+ addStorePathTempRoot();
store.ensurePath(*storePath);
return makeStoreAccessor();
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| store.addTempRoot(*storePath); | |
| std::optional<StorePath> storePath; | |
| if (isFinal() && getNarHash()) | |
| storePath = computeStorePath(store); | |
| bool storePathTempRooted = false; | |
| auto addStorePathTempRoot = [&]() { | |
| if (storePath && !storePathTempRooted) { | |
| store.addTempRoot(*storePath); | |
| storePathTempRooted = true; | |
| } | |
| }; | |
| auto makeStoreAccessor = [&]() -> std::pair<ref<SourceAccessor>, Input> { | |
| auto accessor = store.requireStoreObjectAccessor(*storePath); | |
| @@ | |
| - if (storePath && store.isValidPath(*storePath)) { | |
| - debug("using input '%s' in '%s'", to_string(), store.printStorePath(*storePath)); | |
| if (storePath) { | |
| addStorePathTempRoot(); | |
| if (store.isValidPath(*storePath)) { | |
| debug("using input '%s' in '%s'", to_string(), store.printStorePath(*storePath)); | |
| return makeStoreAccessor(); | |
| } | |
| } | |
| @@ | |
| if (storePath) { | |
| try { | |
| addStorePathTempRoot(); | |
| store.ensurePath(*storePath); | |
| return makeStoreAccessor(); | |
| } |
🤖 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 `@src/libfetchers/fetchers.cc` at line 381, The fast-path in
makeStorePathFromURI still bypasses the temporary-root protection, so the store
can be returned from makeStoreAccessor() without rooting it. Update the
makeStorePathFromURI flow to add the temp root before the early storePath &&
store.isValidPath(*storePath) return path, keeping the protection consistent
with the substitution branch and preserving the existing
requireStoreObjectAccessor() / queryPathInfo() behavior.
Motivation
Based on upstream 0b29401.
Context
Summary by CodeRabbit