I'm sorry you experienced data loss here, but I don't think Go is remiss. The 
only thing in the entire API that refers to stable storage is the Sync call; on 
a correctly-behaving system you do not ever need to call Sync. It is only 
needed if you are protecting against an incorrectly-behaving system. (The 
kernel will always be careful to sync before shutting down, for example.)

Fault tolerance is not just about calling sync now and then; sync is a useful 
tool but it is neither necessary nor sufficient to protect against hardware 
failures, unexpected shutdowns, and the like.

-----Original Message-----
From: golang-nuts@googlegroups.com <golang-nuts@googlegroups.com> On Behalf Of 
Karel Bílek
Sent: Thursday, April 17, 2025 3:01 PM
To: Robert Engels <reng...@ix.netcom.com>
Cc: golang-nuts <golang-nuts@googlegroups.com>
Subject: Re: [go-nuts] Should os.WriteFile call Sync()?

This message was sent by an external party.


> Which is why you need full fsync- which is coordinated all the way 
> down

I don't understand this reply; file.Sync() does fsync syscall on POSIX (and 
with F_FULLFSYNC on macOS).

Yes it's slower, but it's not really documented that it might be necessary. (It 
did cause us trouble in reality when the whole OS crashed for an unrelated 
reason.)

On Thu, 17 Apr 2025 at 16:17, Robert Engels <reng...@ix.netcom.com> wrote:
>
> 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/CAGUkT8bqhzjCqP3i2GTV74F2EYbFcvvmpqZCqh8rYucdG-2Bcw%40mail.gmail.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/dc21e9c0751441049642f0d94ac48efb%40deshaw.com.

Reply via email to