You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
request: add option to call fsync() when closing files #49886
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.
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.
Reacted by Debadree Chatterjee, Yagiz Nizipli and Benjamin Gruenbaum
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.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.
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
6 remaining items
colemickens commentedon Oct 24, 2023
Sorry, I didn't realize that the new option in node 21 was a result of this thread. There's no remaining question, now.
fs: add flush option to writeFile() functions
fs: add flush option to createWriteStream()
fs: add flush option to appendFile() functions
fs: add flush option to writeFile() functions
fs: add flush option to createWriteStream()
fs: add atomic option to writeFile
fs: add atomic option to writeFile
fs: add atomic option to writeFile
fs: add atomic option to writeFile