Repository navigation
request: add option to call fsync() when closing files #49886
Description
Activity
- addedfeature requestIssues requesting new Node.js features.Issues requesting new Node.js features.
on Sep 26, 2023 - addedfsIssues and PRs related to file-system APIs and the fs module.Issues and PRs related to file-system APIs and the fs module.
on Sep 26, 2023 /cc @nodejs/fs
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.I think adding an option to
fs.WriteStreamwould 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.
Reacted by Debadree Chatterjee, Yagiz Nizipli and Benjamin GruenbaumI think writeFile and fs.WriteStream makes sense (especially writeFile)
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.
Reacted by Matteo Collina- added a commit that references this issue
on Oct 4, 2023 6 remaining items
Sorry, I didn't realize that the new option in node 21 was a result of this thread. There's no remaining question, now.
- added 2 commits that reference this issue
on Apr 15, 2024
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 callingfsync().What is the feature you are proposing to solve the problem?
Add an option to the appropriate
fsfunctions (close(),writeFile(), etc.) to callfsync()automatically.What alternatives have you considered?
Flushing the data "by hand."