Closed
Description
What is the problem this feature will solve?
I believe it is possible that Node can close a file and then try to interact with the same file before all of the data has been written to disk. According to the docs for close(2)
this can be fixed by calling fsync()
.
What is the feature you are proposing to solve the problem?
Add an option to the appropriate fs
functions (close()
, writeFile()
, etc.) to call fsync()
automatically.
What alternatives have you considered?
Flushing the data "by hand."
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
aduh95 commentedon Sep 26, 2023
/cc @nodejs/fs
bnoordhuis commentedon Sep 26, 2023
For
fs.writeFile()
that makes sense, it's a sequence of system calls.For
fs.close()
it makes less sense, IMO. Just callfs.fsync()
beforefs.close()
.See also #28513 about interleaving
fs.fsync()
andfs.WriteStream
.mcollina commentedon Sep 27, 2023
I think adding an option to
fs.WriteStream
would be helpful too.@bnoordhuis as a side note, I have been experiencing significant read-after-write issues when using Node.js fs APIs since the move to IO_URING. It's too fast and the filesystem is not flushed.
benjamingr commentedon Sep 27, 2023
I think writeFile and fs.WriteStream makes sense (especially writeFile)
cjihrig commentedon Oct 1, 2023
In addition to
writeFile()
andfs.WriteStream
, there are a few other APIs where this could make sense:appendFile()
- callswriteFile()
under the hood with a modified copy of itsoptions
. This one should Just Work™, but should include tests as well.truncate()
- opens the file, callsftruncate()
, and then closes the file.lchmod()
- opens the file, callsfchmod()
, and then closes the file. I'm less sure if it is necessary here.copyFile()
- this one is tricky because it is implemented several different ways in libuv and Node never has access to the file descriptor.fs: add flush option to writeFile() functions
fs: add flush option to writeFile() functions
fs: add flush option to writeFile() functions
fs: add flush option to createWriteStream()
23 remaining items