Bug 21627 – macOS: std.stdio.File.sync does not guarantee to be written to disk
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
Mac OS X
Creation time
2021-02-10T14:41:52Z
Last change time
2021-03-01T14:31:37Z
Keywords
pull
Assigned to
No Owner
Creator
Hiroki Noda
Comments
Comment #0 by kubo39 — 2021-02-10T14:41:52Z
The documentation(https://dlang.org/phobos/std_stdio.html#.File.sync) says:
> Forces any data buffered by the OS to be written to disk.
> Call flush before calling this function to flush the C FILE buffers first.
Accoriding to macOS's manapge, however, fsync(2) does not guarantee to be written to disk.
https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/fsync.2.html
> Note that while fsync() will flush all data from the host to the drive
> (i.e. the "permanent storage device"), the drive itself may not physically
> write the data to the platters for quite some time and it may be
> written in an out-of-order sequence.
>
> Specifically, if the drive loses power or the OS crashes, the application
> may find that only some or none of their data was written. The disk
> drive may also re-order the data so that later writes may be present,
> while earlier writes are not.
>
> This is not a theoretical edge case. This scenario is easily reproduced
> with real world workloads and drive power failures.
The manpage also says that the F_FULLFSYNC fcntl would be useful in this case.
> For applications that require tighter guarantees about the integrity of
> their data, Mac OS X provides the F_FULLFSYNC fcntl. The F_FULLFSYNC
> fcntl asks the drive to flush all buffered data to permanent storage.
I think std.stdio.File.sync should use F_FULLSYNC fcntl.
Comment #1 by dlang-bot — 2021-02-12T10:25:20Z
@kubo39 created dlang/phobos pull request #7789 "Fix Issue 21627 - macOS: std.stdio.File.sync does not guarantee to be…" fixing this issue:
- Fix Issue 21627 - macOS: std.stdio.File.sync does not guarantee to be written to disk
https://github.com/dlang/phobos/pull/7789
Comment #2 by dlang-bot — 2021-03-01T14:31:37Z
dlang/phobos pull request #7789 "Fix Issue 21627 - macOS: std.stdio.File.sync does not guarantee to be…" was merged into master:
- f0f199066e1a7ce2451edf5813f2bf0b9ed5dc40 by Hiroki Noda:
Fix Issue 21627 - macOS: std.stdio.File.sync does not guarantee to be written to disk
https://github.com/dlang/phobos/pull/7789