fs: make mkstemp disposable #67419
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.37) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 236 lines diff across 2 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.327
Real PR Conversation Timeline
1 comments
"Review active on #67419"
general
weight: 0.35
bakkot
Follow-up to #66484 as requested in #67360.
This adds Explicit Resource Management support to
mkstemp:Changes
1.
lib/fs.js:-
mkstempSync()returns{ path, fd, remove, [Symbol.dispose] }.-
mkstemp()passes{ path, fd, remove, [Symbol.dispose] }to the callback.- Captured full path at call time to remain resistant across
process.chdir().- Repeated calls to
remove()are idempotent; closing the descriptor before disposal catchesEBADF.2.
lib/internal/fs/promises.js:-
mkstemp()returns{ __proto__: null, path, handle, remove, [Symbol.asyncDispose] }.-
remove()awaitshandle.close()followed byunlink(fullPath)(ignoringENOENT).3.
lib/internal/vfs/file_system.js&lib/internal/vfs/setup.js:- Implemented disposal methods on
VirtualFileSystem.prototype.mkstempSyncandpromises.mkstemp.- Preserved disposable return values in VFS handler wrappers.
4. Documentation:
- Updated
doc/api/fs.mdforfsPromises.mkstemp,fs.mkstemp, andfs.mkstempSyncwith disposal methods andusing/await usingexamples.5. Tests:
- Added
test/parallel/test-fs-mkstemp-disposable.jscovering sync, callback, and promise variants for disposal, idempotence, prior manual close, buffer prefixes, andprocess.chdir().- Updated
test/parallel/test-vfs-mkstemp.jsfor VFS disposal coverage.Fixes: https://github.com/nodejs/node/issues/67360
Refs: https://github.com/nodejs/node/pull/66484