From db44044f75a8b6467c37dd99a944e0021a153e6b Mon Sep 17 00:00:00 2001 From: Mauri de Souza Meneguzzo Date: Thu, 7 Mar 2024 14:37:15 +0000 Subject: [PATCH] internal/poll: change Fsync to fallback to syscall.Fsync on darwin In certain scenarios, such as network mounts, 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 replaced with fcntl(fd, F_FULLSYNC). Most SMB servers, like Windows Server and Samba don't support F_FULLSYNC. To avoid such issues fallback to syscall.Fsync if fcntl returns ENOTSUP. Fixes #64215 Change-Id: I567191e1179b7e70ddffb6b881469de1872746ef GitHub-Last-Rev: 62e6931cf79735a192ed57be05005e84720ed232 GitHub-Pull-Request: golang/go#64258 Reviewed-on: https://go-review.googlesource.com/c/go/+/543535 Commit-Queue: Ian Lance Taylor Reviewed-by: Ian Lance Taylor Reviewed-by: Cherry Mui LUCI-TryBot-Result: Go LUCI Auto-Submit: Ian Lance Taylor --- src/internal/poll/fd_fsync_darwin.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/internal/poll/fd_fsync_darwin.go b/src/internal/poll/fd_fsync_darwin.go index 731b7fd5bd..e55b490d41 100644 --- a/src/internal/poll/fd_fsync_darwin.go +++ b/src/internal/poll/fd_fsync_darwin.go @@ -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 }) } -- 2.48.1