internal/poll: change Fsync to fallback to syscall.FSync on darwin

In certain scenarios, such as an SMB mount, calling Fsync
results in ENOTSUP in OSX. This issue was introduced in CL 130676 since
syscall.FSync was not properly flushing contents to disk, and it was
changed to fcntl(fd, F_FULLSYNC). To avoid such issues fallback to
syscall.Fsync if fcntl returns ENOTSUP.

For [reserved]
This commit is contained in:
Mauri de Souza Meneguzzo 2023-11-18 13:20:02 -03:00
parent 3ff5632d63
commit e8088f1bba
1 changed files with 8 additions and 0 deletions

View File

@ -5,6 +5,7 @@
package poll
import (
"errors"
"internal/syscall/unix"
"syscall"
)
@ -19,6 +20,13 @@ func (fd *FD) Fsync() error {
defer fd.decref()
return ignoringEINTR(func() error {
_, err := unix.Fcntl(fd.Sysfd, syscall.F_FULLFSYNC, 0)
// There are scenarios such as SMB mounts where fcntl will fail
// with ENOTSUP. In those cases fallback to fsync.
// See #64215
if err != nil && errors.Is(err, syscall.ENOTSUP) {
err = syscall.Fsync(fd.Sysfd)
}
return err
})
}