Repository navigation
Conversation
yxshee
left a comment
There was a problem hiding this comment.
I checked this out at 34cf949, which is based on current main (2c380d0, 2.5.0), on Node 26.7.0 / macOS.
npm test: 175 passing, 2 pending.npm run lint: clean.- With
storage/disk.jsreverted to main, the open, fsync and close tests fail: the file stays in the upload dir. The abort test passes on main, which is expected since it guards the new branch. - With the fix but without the
if (!file.path) return cb(err)guard, the abort test fails withERR_INVALID_ARG_TYPEfromfs.unlink(undefined). So that guard is covered.
The guard is correct as far as I can tell. finishAbort calls _removeFile on the same file object the engine holds, and _removeFile deletes file.path synchronously. It then defers the unlink through flushingFiles until endFlush runs, which happens before done(err). So whichever side runs second sees no path and skips.
One small thing you could do in this PR: the comment at lib/make-middleware.js:396 ("On error the engine stored nothing and the file has no path") is now true for disk storage only because the engine cleans up after itself. A short note there would help the next reader.
|
Thanks for the thorough review and for validating the regression tests and the I've updated the comment in This is a comment-only change; no behavior was modified. |
|
Checked The full suite passed (175 passing, 2 pending), and lint was clean. All 16 disk-storage tests passed, including the abort-during-flush case with exactly one unlink and an empty upload directory. I also ran the PR's |
|
Thanks for taking the time to test this on Windows and compare the results against the base commit! I really appreciate the additional platform coverage and the thorough verification of the cleanup behavior. |
Summary
Fixes #1504.
When DiskStorage is configured with
flush: true, failures duringfs.open(),fs.fsync(), orfs.close()can leave uploaded files on disk.This PR uses the existing
_removeFile()method to clean up the stored file before propagating the original flush error.It also avoids duplicate cleanup when a request abort has already initiated file removal.
Changes
fs.open(),fs.fsync(),fs.close(), and abort-related cleanup.Testing
npm test— 175 passing, 2 pendingnpm run lint— passedgit diff --check— passedTested locally on macOS with Node.js v24.22.1.
Known limitation
If file removal itself fails, the original flush error is preserved, but the cleanup error is not included in
storageErrors. This change attempts file removal but cannot guarantee cleanup when the underlying filesystem rejects the operation.