Disk Fault Injection: Antithesis Nightmare Mode

Disk fault injection simulating power loss and I/O errors

Antithesis has built a disk fault injection system that simulates power loss, torn writes, I/O errors and slow disks to test whether storage-heavy software really keeps data safe. The company calls it “nightmare mode,” and it grew out of requests from customers whose products can’t afford to lose data.

Why storage code is hard to get right

Teams building databases and similar systems rely on careful tricks: write-ahead logs for recovery, compaction to reclaim space, or writing a new file copy and renaming it over the old one so a change lands completely or not at all. Disks complicate every one of those. A write can fail with an error, and the right reaction depends on why. A full disk may call for compaction. Even creating a file can fail when the filesystem runs out of inodes.

Slowness causes trouble as well. When a read and a write overlap, the reader can see old data, new data or a mix. After a power cut, a later read may find all of a write, part of it or none.

Customers also disagreed on what they expect from storage, and they run ext4, XFS or ZFS, each with different failure behavior. So the Antithesis engineering team built tailored fixes first, such as filling the whole filesystem to test space reclamation, then folded the lessons into one mechanism.

Diagram of a successful write: the program writes data into the kernel page cache, then fsync flushes it to disk.
Image: Antithesis

Power loss is harder than killing a process

Antithesis already could SIGKILL a container, but that is gentle on data. A program’s writes go to the kernel’s page cache and reach disk through writeback, so everything the process handed to the kernel survives a SIGKILL, fsync or not. A real power failure destroys anything the kernel accepted but hadn’t synced.

The simulator can’t unplug a machine, and the kernel offers no way to drop its cache or stop writeback. The team used LazyFS, an open-source filesystem from INESC TEC and Jepsen built on FUSE, which lets a userspace program act as a filesystem. LazyFS keeps written data in its own cache until the program calls fsync. Clearing that cache at the moment the application is killed looks the same as a power cut.

The team considered eBPF, but it can only observe and tweak calls, not hold data and lose it later. A custom block device had the opposite problem: it sits below the filesystem, sees blocks rather than syscalls, and can’t separate synced data from data the kernel happened to write out.

Diagram showing written but unsynced data surviving a SIGKILL: the kernel's writeback still flushes it from the page cache to disk.
Image: Antithesis

From LazyFS to Amnesia

A patched LazyFS ran on several customer tenants for a while and turned up subtle data loss bugs. The team then wrote its own FUSE filesystem, Amnesia, in Rust. It works on inodes, not paths, which makes renames, hard links and deleting open files easier to track. It also never touches a real disk. It keeps volatile and durable state in memory, so an fsync becomes a bookkeeping update, which is faster and just as safe.

Diagram showing a power failure: written but unsynced data in the page cache is lost and never reaches disk.
Image: Antithesis

I/O errors and the fsyncgate bug

Amnesia can return disk I/O errors from syscalls, including EIO on fsync. That one connects to the fsyncgate bug, which led PostgreSQL to crash and recover from its log after a failed fsync instead of retrying. The kernel clears a page’s dirty flag before sending it to the device. If the write fails, fsync returns EIO but the page stays marked clean, so a retried fsync succeeds even though the data never reached disk. Amnesia reproduces that: the retry works, but a later emulated power failure loses the data unless the program writes it again.

Latency faults for race conditions

Two kinds of slow-disk fault target concurrency bugs. One lets the fuzzer choose the order in which operations complete, parking some with a deadline. The other splits a write into small chunks and lets the fuzzer apply only some, so a racing read sees a patchwork of old and new data, as it could on ext4. Every combination is a legal interleaving the kernel or disk could produce.

Picking the moments to cut power

The fault injector works with the Antithesis fuzzer, so disk faults are controlled like its other faults. A power failure can land before a syscall, during it or after it. Timing inside “before” or “after” doesn’t change the outcome, while the interesting “during” states are short and easy to miss. So the injector decides per syscall and fires at one of three points: before any of the operation is applied, after part of it, or after all of it.

What to expect next

Torn writes, where the disk persists data in different units or order than a program expects, are covered by the same design. Teams that test storage code should check their assumptions about fsync and rename-based updates, since those are the areas where simulated failures are most likely to expose gaps.

Source: Antithesis

Written by

Saksham Bhargava

Saksham Bhargava runs Alteroid and has been writing about consumer technology for over five years, covering iPhone, Android, Windows, AI tools and gaming. With an MCA and six years of hands-on web development experience, he tests the features he writes about on his own devices and focuses on clear, practical guides that solve real problems. Away from the screen, he enjoys travelling to places most tourists skip.