Repository navigation
fix(fs): register the atomic-write temp file before creating it - #15593
Conversation
write_atomic let NamedTempFile pick the random name while creating the file, so the registration could only follow the create and an interrupt in between left the temp file behind. tempfile's Builder::make_in hands the chosen name to a closure, which now registers it and then creates the file exclusively with mode 0600, as NamedTempFile did. The cross-process test now interrupts as soon as the temp file exists, which covers that earliest window. Also shrink the lockfile cleanup test's payload to 64 MiB and allow it ten attempts to catch a save in flight. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Warning Review limit reachedNext included review available in 1 minute. View limit detailsLimit details: You’ve used all 10 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository: pnpm/pnpm/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #15593 +/- ##
========================================
Coverage 91.81% 91.82%
========================================
Files 1435 1438 +3
Lines 193989 194154 +165
========================================
+ Hits 178111 178281 +170
+ Misses 15878 15873 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Micro-Benchmark ResultsLinux |
Same-run regression checkHEAD and main are measured on the same runner. The tolerance is 5% of the main median or 2 ms, whichever is larger. A regression requires both the median slowdown and the gap between the fastest retained HEAD sample and slowest retained main sample to exceed this tolerance, after trimming up to 10% from each tail. Suspected regressions are rerun once with target order reversed and only fail if reproduced. This conservative noise guard is not a statistical confidence interval. Inconclusive rows do not fail the check. They remain visible for performance review. Bencher retains absolute minimum timings for historical tracking; historical alerts do not gate this PR. Sequential measurements can still be affected by runner drift.
Integrated-Benchmark Report (Linux)Commit: Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm; the linked-workspace scenario compares current Rust against main Rust. Bencher consumes pacquet@HEAD and pnpr@HEAD. The tables below show mean ± σ. Bencher tracks absolute minimum latency; PR regression checks compare HEAD and main samples from the same runner. Historical timing alerts do not gate PRs. Scenario: Isolated linker: fresh restore, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 2.6279196479599998,
"stddev": 0.19281039094711755,
"median": 2.6028151696600004,
"user": 2.25027316,
"system": 2.0832032,
"min": 2.39149046516,
"max": 2.93492286816
},
{
"command": "pacquet@main",
"mean": 2.37047850866,
"stddev": 0.03556638136489856,
"median": 2.36371902566,
"user": 1.63697326,
"system": 1.5091146,
"min": 2.3234607881600002,
"max": 2.4220327361600003
},
{
"command": "pnpr@HEAD",
"mean": 1.4607546330599999,
"stddev": 0.12500417313619222,
"median": 1.42868181716,
"user": 1.50524616,
"system": 1.4817500999999997,
"min": 1.30765165816,
"max": 1.69214662816
},
{
"command": "pnpr@main",
"mean": 1.5508946681599998,
"stddev": 0.1029931671396743,
"median": 1.5451103856600001,
"user": 1.6422874599999997,
"system": 1.6319861,
"min": 1.42037632116,
"max": 1.69740633816
}
]
}Scenario: Isolated linker: fresh restore, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.32528667908000003,
"stddev": 0.0233345095509245,
"median": 0.31669183428000003,
"user": 0.36200953999999996,
"system": 0.7085004199999999,
"min": 0.30044550128,
"max": 0.37031615828000003
},
{
"command": "pacquet@main",
"mean": 0.31612117677999996,
"stddev": 0.021981348937095798,
"median": 0.32328388078000003,
"user": 0.35292594,
"system": 0.7019841199999999,
"min": 0.28487334428,
"max": 0.35169509728000004
},
{
"command": "pnpr@HEAD",
"mean": 0.37165251628000007,
"stddev": 0.025923210084172737,
"median": 0.36931280628,
"user": 0.38990823999999996,
"system": 0.75046112,
"min": 0.33545204928,
"max": 0.42157192928000004
},
{
"command": "pnpr@main",
"mean": 0.32341694748,
"stddev": 0.0598647494194494,
"median": 0.29667756878,
"user": 0.35085544,
"system": 0.68089912,
"min": 0.27110571328,
"max": 0.46506084128
}
]
}Scenario: Isolated linker: repeat install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.009897507742857149,
"stddev": 0.0009799815734284367,
"median": 0.009858062099999999,
"user": 0.005792350634920632,
"system": 0.004662574444444443,
"min": 0.0070373461,
"max": 0.0130905031
},
{
"command": "pacquet@main",
"mean": 0.010772367074264695,
"stddev": 0.0015009907502099348,
"median": 0.010560956600000001,
"user": 0.006233694044117646,
"system": 0.005161796249999999,
"min": 0.0082880131,
"max": 0.0205551391
},
{
"command": "pnpr@HEAD",
"mean": 0.011424450046666665,
"stddev": 0.0024559163910430333,
"median": 0.0109391696,
"user": 0.006941146666666665,
"system": 0.005117616133333335,
"min": 0.0075226711,
"max": 0.0239180971
},
{
"command": "pnpr@main",
"mean": 0.01199828980081967,
"stddev": 0.0024261521259482575,
"median": 0.0112242321,
"user": 0.006899692295081964,
"system": 0.005692963032786888,
"min": 0.0092431631,
"max": 0.0236908291
}
]
}Scenario: Isolated linker: repeat install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.015476271458644067,
"stddev": 0.002735568906436452,
"median": 0.01497229034,
"user": 0.007588056949152541,
"system": 0.008759813220338983,
"min": 0.011079265840000001,
"max": 0.02134995384
},
{
"command": "pacquet@main",
"mean": 0.015496067763611118,
"stddev": 0.0027896904632305256,
"median": 0.01563847634,
"user": 0.007825671944444449,
"system": 0.008547144444444443,
"min": 0.00948405884,
"max": 0.02102665184
},
{
"command": "pnpr@HEAD",
"mean": 0.018980842620487808,
"stddev": 0.006945342535718754,
"median": 0.01754308534,
"user": 0.010018155609756106,
"system": 0.009879990975609753,
"min": 0.010017342840000002,
"max": 0.050395905840000005
},
{
"command": "pnpr@main",
"mean": 0.011625762387263686,
"stddev": 0.0021522562258200254,
"median": 0.01106318484,
"user": 0.006424800796019896,
"system": 0.005977880597014925,
"min": 0.00867501684,
"max": 0.01885299284
}
]
}Scenario: Isolated linker: fresh install, cold cache + cold store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 3.4630367529400004,
"stddev": 0.22955383123379575,
"median": 3.42397774974,
"user": 3.83160502,
"system": 2.82876604,
"min": 3.1327836177400004,
"max": 3.80690949974
},
{
"command": "pacquet@main",
"mean": 3.27734303584,
"stddev": 0.07167325527875835,
"median": 3.26650250474,
"user": 3.6255271199999997,
"system": 2.75666704,
"min": 3.18182022474,
"max": 3.4036024187400002
},
{
"command": "pnpr@HEAD",
"mean": 1.9404659591400002,
"stddev": 0.11960880821262666,
"median": 1.9599302837400001,
"user": 2.0926290199999995,
"system": 2.17976144,
"min": 1.7075027217399998,
"max": 2.1002670837400004
},
{
"command": "pnpr@main",
"mean": 1.7336069590399998,
"stddev": 0.1203007273980838,
"median": 1.69883229874,
"user": 1.9807507199999996,
"system": 2.00042564,
"min": 1.58899421474,
"max": 1.9751190937399998
}
]
}Scenario: Isolated linker: fresh install, hot cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.64600487434,
"stddev": 0.07207157031419552,
"median": 0.6484910042400001,
"user": 0.9392749199999999,
"system": 0.93315126,
"min": 0.51546425224,
"max": 0.7877655292400001
},
{
"command": "pacquet@main",
"mean": 0.67341119934,
"stddev": 0.09280178359150315,
"median": 0.68335410974,
"user": 0.9994037199999999,
"system": 0.97526896,
"min": 0.5470693752400001,
"max": 0.8624092212400001
},
{
"command": "pnpr@HEAD",
"mean": 0.49976985764000015,
"stddev": 0.05439199117413661,
"median": 0.48850449774000004,
"user": 0.4554609199999999,
"system": 0.78400896,
"min": 0.41084753924000006,
"max": 0.58410628224
},
{
"command": "pnpr@main",
"mean": 0.50367477114,
"stddev": 0.0340338418440445,
"median": 0.4939471712400001,
"user": 0.46450401999999996,
"system": 0.7858983599999999,
"min": 0.4727706802400001,
"max": 0.58558722324
}
]
}Scenario: Isolated linker: fresh install, cold cache + hot store
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 1.8314845891999998,
"stddev": 0.11231504981993724,
"median": 1.8134950699999999,
"user": 1.2742767,
"system": 1.0523540799999997,
"min": 1.6976471245,
"max": 2.0972168225
},
{
"command": "pacquet@main",
"mean": 1.9482518495999996,
"stddev": 0.08572463082213293,
"median": 1.926650106,
"user": 1.5028551999999997,
"system": 1.1244656799999997,
"min": 1.8230519985,
"max": 2.1010263824999997
},
{
"command": "pnpr@HEAD",
"mean": 0.4255005691,
"stddev": 0.0597102671764733,
"median": 0.447526458,
"user": 0.36117889999999997,
"system": 0.71977778,
"min": 0.3358842375,
"max": 0.4932188325
},
{
"command": "pnpr@main",
"mean": 0.3617073902,
"stddev": 0.040628887467973655,
"median": 0.3682611265,
"user": 0.31254339999999997,
"system": 0.6504394800000001,
"min": 0.2987775795,
"max": 0.4325771925
}
]
}Scenario: Isolated linker: fresh resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.24659957761666665,
"stddev": 0.020743516502379027,
"median": 0.23893658620000002,
"user": 0.26195508666666667,
"system": 0.08352183333333331,
"min": 0.2253711952,
"max": 0.28729231920000003
},
{
"command": "pacquet@main",
"mean": 0.23751876096923083,
"stddev": 0.02438889646095837,
"median": 0.2300867262,
"user": 0.2476151123076923,
"system": 0.07471611538461537,
"min": 0.21248030220000003,
"max": 0.3012955842
},
{
"command": "pnpr@HEAD",
"mean": 0.10087646576666667,
"stddev": 0.007320090511154137,
"median": 0.0977849107,
"user": 0.040970653333333336,
"system": 0.017646366666666666,
"min": 0.09289324820000001,
"max": 0.1181424902
},
{
"command": "pnpr@main",
"mean": 0.09566691842222222,
"stddev": 0.0034367589651631693,
"median": 0.09591849020000001,
"user": 0.03404986444444445,
"system": 0.0164902037037037,
"min": 0.08929290520000001,
"max": 0.1053593002
}
]
}Scenario: Isolated linker: peer-heavy resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.985526849748889,
"stddev": 0.14456974184613,
"median": 1.02316152286,
"user": 1.000816624444444,
"system": 0.2912160244444444,
"min": 0.7187743508600001,
"max": 1.19827278386
},
{
"command": "pacquet@main",
"mean": 0.9465724175266668,
"stddev": 0.17602727367359638,
"median": 0.9608770308600001,
"user": 0.9401688466666668,
"system": 0.26844357999999996,
"min": 0.60274878486,
"max": 1.1623506488600002
},
{
"command": "pnpm@HEAD",
"mean": 4.693224320637778,
"stddev": 0.6082489257654011,
"median": 4.50455242586,
"user": 7.043356735555555,
"system": 0.4307170244444445,
"min": 3.8604628118599997,
"max": 5.71053769386
}
]
}Scenario: Isolated linker: linked-workspace resolve, hot cache, offline
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.28915167476000003,
"stddev": 0.05333250079660625,
"median": 0.27654811676,
"user": 0.24320249666666663,
"system": 0.10740704333333334,
"min": 0.22846215326000002,
"max": 0.39420991826
},
{
"command": "pacquet@main",
"mean": 0.32561586116,
"stddev": 0.046380276934914394,
"median": 0.33522517376000005,
"user": 0.26017908,
"system": 0.13557446,
"min": 0.26092925226,
"max": 0.38094703726
}
]
}Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 4.674244034760001,
"stddev": 0.20868990861880155,
"median": 4.618932861859999,
"user": 2.1418519399999996,
"system": 1.8326986600000001,
"min": 4.42947572836,
"max": 5.02945968336
},
{
"command": "pacquet@main",
"mean": 4.70836181336,
"stddev": 0.29359891762434814,
"median": 4.63189643686,
"user": 2.16330984,
"system": 1.88169956,
"min": 4.45782622236,
"max": 5.37542519336
},
{
"command": "pnpr@HEAD",
"mean": 3.65385514046,
"stddev": 0.1668600710402365,
"median": 3.62533745586,
"user": 1.94520814,
"system": 1.7959794599999999,
"min": 3.4642317183599998,
"max": 3.95914177936
},
{
"command": "pnpr@main",
"mean": 3.8447432831599997,
"stddev": 0.208124406149008,
"median": 3.80292022486,
"user": 2.26450734,
"system": 2.1029941599999997,
"min": 3.60918943536,
"max": 4.20971035736
}
]
}Scenario: GVS linker: fresh restore, hot cache + hot storeSame install as the isolated fresh-restore hot/hot scenario, into the shared virtual store, the layout pnpm 12 installs into by default. Scenarios run on separate machines, so compare main and branch within each table.
BENCHMARK_REPORT.json{
"results": [
{
"command": "pacquet@HEAD",
"mean": 0.13118450287789477,
"stddev": 0.009540867164587845,
"median": 0.13092233472,
"user": 0.16778081894736843,
"system": 0.13477114736842102,
"min": 0.11696238472,
"max": 0.15649939672000002
},
{
"command": "pacquet@main",
"mean": 0.15194610881999998,
"stddev": 0.024263740429552615,
"median": 0.14777369372000002,
"user": 0.18920004000000004,
"system": 0.13940034999999998,
"min": 0.12224426172000001,
"max": 0.21554053772
},
{
"command": "pnpr@HEAD",
"mean": 0.1447953418964706,
"stddev": 0.005850255085920143,
"median": 0.14438971972,
"user": 0.17298306352941176,
"system": 0.13749196470588232,
"min": 0.13416148672,
"max": 0.15343445172
},
{
"command": "pnpr@main",
"mean": 0.14898801005333334,
"stddev": 0.011244595096652472,
"median": 0.14387806972,
"user": 0.17751710666666665,
"system": 0.14652533333333334,
"min": 0.13217372372000002,
"max": 0.17037660972000002
}
]
} |
PR Summary by QodoRegister atomic temp files before creation
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
|
On Qodo's summary finding 2 (registering before Written by an agent (Claude Code, claude-opus-5-5). |
|
@coderabbitai review |
|
|
@coderabbitai review |
|
…#15593) write_atomic let NamedTempFile pick the random name while creating the file, so the registration could only follow the create and an interrupt in between left the temp file behind. tempfile's Builder::make_in hands the chosen name to a closure, which now registers it and then creates the file exclusively with mode 0600, as NamedTempFile did. The cross-process test now interrupts as soon as the temp file exists, which covers that earliest window. Also shrink the lockfile cleanup test's payload to 64 MiB and allow it ten attempts to catch a save in flight.
Summary
Follow-up to #15486, carrying two fixes from its last review round that were ready after it merged.
pnpm_fs::write_atomicletNamedTempFilechoose the random name while creating the file, so the temp file could only be registered with the interrupt cleanup after it existed. An interrupt in that gap left it behind. It now usestempfile::Builder::make_in, whose closure receives the chosen name before the file exists. The closure registers the name, then creates the file withcreate_newand mode 0600, the modeNamedTempFileused. The cross-process test now interrupts as soon as the temp file exists, instead of waiting for content. It cannot pin down the order of registration and create, since the child is polled from another process, so the ordering itself rests on the code inwrite_tmp_over.This affects only the Rust CLI. The TypeScript writer already registers its exit callback before
fs.open(tempPath, 'wx'). There is no changeset, because the cleanup from #15486 has not been released yet.Squash Commit Body
Checklist
are implemented in every affected version.
Written by an agent (Claude Code, claude-opus-5-5).
🤖 Generated with Claude Code