Don't defer Close() on writable files

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

InfluxDB – Built for High-Performance Time Series Workloads
InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.
www.influxdata.com
featured
SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  1. zig

    General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.

    Arguably, one should call `flush()` on the file first. Resource allocation must always succeed; otherwise a lot of invariants break. This is why Zig's close method[0] ignores errors (with the exception of `EBADF`).

    [0]: https://github.com/ziglang/zig/blob/fb0028a0d7b43a2a5dd05f07...

  2. InfluxDB

    InfluxDB – Built for High-Performance Time Series Workloads. InfluxDB 3 OSS is now GA. Transform, enrich, and act on time series data directly in the database. Automate critical tasks and eliminate the need to move data externally. Download now.

    InfluxDB logo
  3. rfcs

    RFCs for changes to Rust

    That nobody has gone through the effort of collating its requirements and writing an RFC after https://github.com/rust-lang/rfcs/pull/770 was closed (back in 2015).

    I assume a big issue is that this is full of edge cases up the ass, and the value is somewhat limited in the sense that if you know you want durable writes you'll sync() and know you're fucked if you get an error, but close() does not guarantee a sync to disk, as the linux man page indicates:

    > A successful close does not guarantee that the data has been successfully saved to disk, as the kernel uses the buffer cache to defer writes.

  4. lucene

    Apache Lucene open-source search software

    "if you are creating a file, to ensure full synchronisation you also need to fsync the parent directory, otherwise the file can be fsynced but the update to the directory lost."

    And if you need this in Java you still have resort to ugly hacks.

    https://github.com/apache/lucene/issues/7231

  5. MySQL

    MySQL Server, the world's most popular open source database, and MySQL Cluster, a real-time, open source transactional database.

  6. safefile

    Go package safefile implements safe "atomic" saving of files.

    It doesn't really break the described scenario (implemented in my package https://github.com/dchest/safefile), because its guarantee is that the write is atomic, not that the write will not fail. Atomic means that either file is created/replaced fully or not created/not replaced at all. That is, no partial write is done. It doesn't protect against power failures (did disk firmware write out the contents after the OS commanded it to? Did OS perform fsync of file and fsync of directory in the correct order?), and fsyncing the parent directory only works on certain filesystems (I assume ZFS will have to sync the whole dnode tree before power failure).

  7. CppCoreGuidelines

    The C++ Core Guidelines are a set of tried-and-true guidelines, rules, and best practices about coding in C++

    > close a file (which ironically is the poster child for RAII)

    Yes, I call this "RAII is a lie" (T-shirt pending).

    Closing file descriptors is univerally used to showcase RAII, but it should never be used for that.

    C++ has the same problem:

    https://github.com/isocpp/CppCoreGuidelines/issues/2203

    In there, it is acknowledged that a manual Close() should always be provided, and used if you want guarantees.

    > is a bad pattern

    Good that Rust at least figured it out early that it's a bad pattern!

    Never use RAII in situations where the cleanup can fail!

  8. SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Tail Call Recursion in Java with ASM (2023)

    2 projects | news.ycombinator.com | 30 Mar 2025
  • Crabtime: Zig's Comptime in Rust

    6 projects | news.ycombinator.com | 22 Mar 2025
  • When Zig is safer and faster than (unsafe) Rust

    3 projects | /r/rust | 7 Mar 2023
  • I've been learning Rust for 3 days and this is my first impression

    4 projects | /r/ProgrammerHumor | 5 Mar 2023
  • Linus Torvalds: Rust For The Kernel Could Possibly Be Merged For Linux 5.20

    4 projects | /r/programming | 21 Jun 2022