Repository navigation
fix(prerender): write output files atomically - #4488
sobol-sudo wants to merge 6 commits into
Conversation
|
@sobol-sudo is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/utils/fs.ts (1)
54-56: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove implementation-explaining comments.
The code is self-explanatory; these comments violate the source-file guideline. As per coding guidelines, “Do not add comments explaining what the line does unless prompted.”
🤖 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/utils/fs.ts` around lines 54 - 56, Remove the implementation-explaining comment above the sibling temporary-file write and rename logic in the filesystem utility, leaving the underlying atomic write behavior unchanged.Source: Coding guidelines
test/unit/fs.test.ts (1)
26-30: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover cleanup after a failed replacement.
This only tests successful cleanup after
rename. Add a test that forces the post-write replacement to fail and verifies the sibling temporary file is removed, as required by the PR objective.🤖 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 `@test/unit/fs.test.ts` around lines 26 - 30, Add a failure-path test alongside “leaves no temporary files behind” that forces the post-write replacement/rename to fail, then verifies the sibling temporary file is removed from dir. Reuse the existing filesystem helper and temporary-file naming behavior, and assert cleanup occurs after the write operation rejects.
🤖 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.
Nitpick comments:
In `@src/utils/fs.ts`:
- Around line 54-56: Remove the implementation-explaining comment above the
sibling temporary-file write and rename logic in the filesystem utility, leaving
the underlying atomic write behavior unchanged.
In `@test/unit/fs.test.ts`:
- Around line 26-30: Add a failure-path test alongside “leaves no temporary
files behind” that forces the post-write replacement/rename to fail, then
verifies the sibling temporary file is removed from dir. Reuse the existing
filesystem helper and temporary-file naming behavior, and assert cleanup occurs
after the write operation rejects.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 147c1344-e67e-4c9b-943d-388f2fe4c419
📒 Files selected for processing (2)
src/utils/fs.tstest/unit/fs.test.ts
0551607 to
607a830
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Thanks for this, and for the very clear write-up. Rebase I rebased the branch onto the latest Review I checked the fix and it looks correct.
I also confirmed the regression test really is a regression test. I put the old non-atomic What I added One small commit on top: a test for the cleanup path. Your tests covered the happy path, but nothing covered the Notes for the maintainers, not things you need to change
Leaving the dedup half out was the right call in my opinion, and your #4491 covers it. This comment was written by an AI assistant on behalf of the Nitro maintainers. Please double-check anything that looks wrong. |
commit: |
Keep the shared `writeFile` in place-write semantics for build info, presets and the dev worker entry. Name the temp file independently of the target so near-limit file names still fit, and retry the rename on Windows when another process transiently holds the destination open.
🔗 Linked issue
Resolves the "not written atomically" half of #4487. The dedup half landed in #4491.
❓ Type of change
📚 Description
With
prerender.concurrency > 1, two writes to one output file can overlap.fs.writeFiletruncates and writes in place, so the file can end up torn between both payloads: the shorter body followed by the longer one's tail. This is the corruption reported in #4487.#4491 claims each output path before writing, so routes resolving to the same path no longer race. Routes with different paths can still alias one file, for example
/Aboutand/abouton a case-insensitive filesystem (macOS, Windows).This adds
writeFileAtomicinsrc/utils/fs.tsand uses it only for prerendered output. It writes to a temp file in the same directory and renames it into place.renameis atomic within a filesystem, so overlapping writers give last-one-wins instead of a torn file..nitro-<random>.tmp, independent of the target name, so target names close to the 255-byte limit still fit.EPERM/EACCES/EBUSY(antivirus or indexers holding the destination open).writeFile(build info, presets, dev worker entry) is unchanged and still writes in place.The extra
renameper file is within noise when writing 5000 files at concurrency 10.📝 Checklist
test/unit/fs.test.tscovers basic writes, overwrites, near-limit file names, temp file cleanup on failure, and concurrent writers (fails onmain, passes with this change).🤖 Generated with AI assistant