Even if the OS writes it to disk there is the possibility of failure due to lazy writes by the drive itself. Which is why you need full fsync- which is coordinated all the way down. It is also many orders of magnitude slower. See this for performance difference details https://github.com/robaho/cpp_leveldb?tab=readme-ov-file#performance

On Apr 16, 2025, at 6:09 PM, Karel Bílek <k...@karelbilek.com> wrote:

I was quite surprised recently that, at least on linux, file.Close() does not guarantee file.Sync(); in some edge-cases, files can be not put properly to filesystem.

If the data integrity is critical, it seems better to call file.Sync() before file.Close().

(Linux has this in close / fsync syscall manpages.)

I am surprised that the docs don't mention this; also, that os.WriteFile does not call file sync, so even when os.WriteFile() returns no error, it doesn't mean the file is actually written on the disk!

I have 2 questions

1) should this be documented in godoc somewhere?
2) should os.WriteFile explicitly call fsync?


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/dd574b31-8146-4710-9937-a56e8ecbe428n%40googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/019AC13F-8A75-4A8C-A9F9-B7A3DE9DA8D8%40ix.netcom.com.

Reply via email to