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
Mount a SMB share on macOS that supports fsync (strict sync = yes, the default since Samba 4.7.0)
Open a file on that share
Call file.Sync()
What did you expect to see?
No error. The fsync instruction is passed down to the network share, which takes action (or not, depending on its configuration)
What did you see instead?
Error: ENOTSUP
It appears that a change was implemented in go1.12 for #26650 which switched File.Sync() to call fcntl(fd, F_FULLFSYNC) rather than fsync(fd). This was due to fsync not being implemented as expected on darwin.
On local volumes, this change appears to work correctly. However, F_FULLFSYNC appears to be unsupported on SMB volumes--and likely elsewhere too.
This means that the change as a result of #26650 leads to ENOTSUP being returned where a Sync would have succeeded before.
(I've verified via samba logging that calling unix.Fsync() on the fd results in the correct fsync instruction being sent to the server, so darwin's wonky fsync() behaviour seems to only apply to local volumes)
I'd bet that most Go developers are not testing file operations in SMB mounts, so are shipping software that would have worked in 1.11, but in 1.12+ will fail.
I've had to resort to a workaround:
funcsync(f*os.File) error {
err:=f.Sync()
// Ensure fsync is called if Sync is not supported. There are scenarios (SMB mounts, ...?) where fsync will succeed but Sync will fail dueif (runtime.GOOS=="darwin"||runtime.GOOS=="ios") &&errors.Is(err, syscall.ENOTSUP) {
err=unix.Fsync(int(file.Fd()))
}
returnerr
}
The text was updated successfully, but these errors were encountered:
Thanks. It seems plausible to default to fsync if we get ENOTSUP in those platforms.
/cc @golang/darwin
seankhliao
changed the title
os/File: Sync() returns ENOTSUP on network mounts that support fsync
os: File.Sync() returns ENOTSUP on network mounts that support fsync
Nov 17, 2023
mauri870
added
NeedsFix
The path to resolution is known, but the work has not been done.
and removed
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
labels
Nov 18, 2023
This is a bug in internal/poll.Fsync (os.File.Sync() as well) on darwin that only affect SMB mounts. There is no way around it AFAIK and it has been around circa 2018, after CL 130676 was merged.
Given that we entered a freeze, I want to check if the proposed fix at CL 543535 is worth submitting for 1.22 and if this bug deserves backports for 1.20 and 1.21.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
strict sync = yes
, the default since Samba 4.7.0)file.Sync()
What did you expect to see?
No error. The fsync instruction is passed down to the network share, which takes action (or not, depending on its configuration)
What did you see instead?
Error:
ENOTSUP
It appears that a change was implemented in go1.12 for #26650 which switched File.Sync() to call
fcntl(fd, F_FULLFSYNC)
rather thanfsync(fd)
. This was due to fsync not being implemented as expected on darwin.On local volumes, this change appears to work correctly. However,
F_FULLFSYNC
appears to be unsupported on SMB volumes--and likely elsewhere too.This means that the change as a result of #26650 leads to
ENOTSUP
being returned where a Sync would have succeeded before.(I've verified via samba logging that calling
unix.Fsync()
on the fd results in the correct fsync instruction being sent to the server, so darwin's wonky fsync() behaviour seems to only apply to local volumes)I'd bet that most Go developers are not testing file operations in SMB mounts, so are shipping software that would have worked in 1.11, but in 1.12+ will fail.
I've had to resort to a workaround:
The text was updated successfully, but these errors were encountered: