Test disk-full failures without filling the production volume

Test disk-full failures without filling the production volume

Test disk-full failures without filling the production volume

A batch export stops halfway through with “No space left on device.” The process exits, but the destination file already exists. On the next run, the application may mistake that incomplete file for a successful result—or keep retrying and disrupt the database and logs on the same volume. A disk-full drill is not just about triggering an error. It should establish how failures surface, whether existing data survives, and whether work can resume once space is available again.

The two 1TB NVMe drives in HttpNode dedicated servers are directly attached, with no hardware RAID; users are responsible for application error handling and data backups. This guide uses a separate ext4 filesystem image on Debian 12. It does not change partitions or continuously fill a volume that holds production data. Run these commands in a test environment with administrative privileges.

1. Define the failure scope and acceptance criteria

Have e2fsprogs, util-linux, python3, and standard checksum tools available. Before starting, check the capacity of the filesystem containing /var/tmp. Leave enough headroom for this drill’s 128MiB image and for other workloads to grow. If the real filesystem is already nearly full, stop the drill.

This test covers exhausted block space only—not inode exhaustion, user quotas, underlying device failures, or sudden power loss. There are four acceptance criteria: capture the exact error code; retain the failed file so its length can be inspected; confirm that existing files have not changed; and complete a new synchronized write and readback after cleanup.

A sparse image is not a “zero-space sandbox.” Writing data inside the image also consumes space on the real filesystem that contains it. The image isolates the capacity boundary, not the underlying resource consumption.

Do not use a database directory, a host storage pool, or a path that is actively receiving uploads as the drill directory. Do not substitute a reboot for recovery verification, either: that would make it impossible to tell whether freeing space or restarting the process changed the outcome.

2. Create a separate ext4 test volume

Run the following commands in order in the same administrative shell. If any step fails, investigate before continuing:

df -h /var/tmp
export LAB="$(mktemp -d /var/tmp/enospc-lab.XXXXXX)"
mkdir "$LAB/fs"
truncate -s 128M "$LAB/disk.img"
mkfs.ext4 -q -m 0 "$LAB/disk.img"
mount -o loop,nosuid,nodev,noexec "$LAB/disk.img" "$LAB/fs"
findmnt -T "$LAB/fs"
df -h "$LAB/fs"
df -i "$LAB/fs"

The target of mkfs.ext4 is the regular file you just created. Do not replace it with a real block device. The -m 0 option removes reserved blocks from this test volume to make its capacity boundary easier to observe; it is not a general recommendation for production filesystems. The mount restrictions reduce the risk of unintended execution, but do not provide a complete security sandbox.

Establish a baseline for existing data

Create a small baseline file, synchronize it, and then save its checksum manifest outside the test volume. This keeps the manifest readable even when the volume is full:

printf 'baseline-v1\n' > "$LAB/fs/baseline.txt"
sync -f "$LAB/fs"
(
  cd "$LAB/fs"
  sha256sum baseline.txt
) > "$LAB/baseline.sha256"

Check that the mount target shown by findmnt is indeed the dedicated directory. If the image is not mounted correctly, subsequent writes will fill the outer filesystem instead, defeating the drill’s intended boundary.

3. Trigger ENOSPC and identify the failure stage

The program below writes one block at a time and calls fsync after each round. It also handles short writes and treats only ENOSPC as the expected failure. Any other error is raised directly; it must not be lumped together with “disk full.”

import errno
import os
from pathlib import Path

target = Path(os.environ["LAB"]) / "fs" / "filler.bin"
block = b"x" * (1024 * 1024)
accepted = 0
stage = "open"

try:
    with target.open("xb", buffering=0) as stream:
        while True:
            pending = memoryview(block)
            while pending:
                stage = "write"
                written = stream.write(pending)
                if written is None or written <= 0:
                    raise RuntimeError("Write made no progress")
                accepted += written
                pending = pending[written:]
            stage = "fsync"
            os.fsync(stream.fileno())
except OSError as exc:
    if exc.errno != errno.ENOSPC:
        raise
    print(f"expected=ENOSPC stage={stage} accepted={accepted}")
else:
    raise RuntimeError("Expected ENOSPC was not observed")

Save the code as $LAB/fill.py and run python3 "$LAB/fill.py". The code resides outside the mounted volume, so it is not subject to its noexec restriction. The program uses exclusive creation mode: if a file from an earlier run is still present, it fails rather than silently overwriting the previous test evidence.

A successful write does not make the entire result valid

accepted counts only the bytes accepted by write calls—not bytes committed as a business transaction. Lack of space may surface during write or, because of delayed allocation, during synchronization. Any partial data written in the final round cannot automatically be treated as a valid export.

A real application should retain the failure stage and destination path and report failure to the caller. It must not log an error and then continue reporting success. If the output format includes a trailing index, a record count, or a checksum field, use the appropriate reader to verify completeness; checking that the file exists is not enough.

4. Preserve the evidence, then check space and data

After the failure, perform read-only checks first. Do not rush to delete the filler file:

stat -c '%n %s bytes' "$LAB/fs/filler.bin"
df -h "$LAB/fs"
df -i "$LAB/fs"
(
  cd "$LAB/fs"
  sha256sum -c "$LAB/baseline.sha256"
)

You should see block space nearly exhausted, inodes still available, and a successful baseline checksum check. Display rounding may make df -h appear to show a little free space; that does not invalidate ENOSPC. Filesystem metadata and allocation granularity also affect how much data can be written.

Once the program has exited, its file handle is closed. Now delete the filler file and synchronize the filesystem:

rm -- "$LAB/fs/filler.bin"
sync -f "$LAB/fs"
df -h "$LAB/fs"

If free space does not increase, first check whether a process still holds a deleted file open. Do not proceed by deleting other files in bulk. Next, run a separate recovery probe:

import os
from pathlib import Path

root = Path(os.environ["LAB"]) / "fs"
payload = b"recovery-ok\n" * 4096
with (root / "recovered.bin").open("xb") as stream:
    if stream.write(payload) != len(payload):
        raise RuntimeError("Short recovery write")
    stream.flush()
    os.fsync(stream.fileno())
if (root / "recovered.bin").read_bytes() != payload:
    raise RuntimeError("Recovery verification failed")
print("recovery=passed")

Only when a new file can be opened, written in full, synchronized, and read back has the test path returned to a usable state. This does not prove durability under power loss, nor does it replace acceptance testing of the real application.

5. Include the application in the drill and clean up

For application-level testing, deploy an isolated instance and point only its temporary output directory at the test volume. Do not directly switch the production database path. Limit the size of the test input and keep the instance isolated from external requests and real message queues, so retries cannot turn a simulated failure into duplicate business operations.

Check at least three outcomes: whether a write failure produces an unambiguous exit code or API status; whether a failed artifact is mistakenly published; and whether a retry after freeing space creates duplicate records. If the application switches to read-only mode or pauses message consumption, follow its recovery procedure and record whether manual intervention is required.

Finally, verify the baseline again, confirm that no process is using the test directory, and then clean up:

(
  cd "$LAB/fs"
  sha256sum -c "$LAB/baseline.sha256"
)
umount "$LAB/fs"

Continue with the following commands only after the unmount succeeds:

rmdir "$LAB/fs"
rm -- "$LAB/disk.img" "$LAB/baseline.sha256" "$LAB/fill.py"
rmdir "$LAB"
unset LAB

If unmounting fails, preserve the test state. Do not force an unmount to bypass resources that are still in use. Keep a drill record containing the failure stage, failed file length, space usage changes, baseline checksum verification, and recovery results. The goal is not to prove that “the program encountered a full disk,” but that failure was not disguised as success and that correct writing really resumed after cleanup.

Frequently asked questions

Should a disk-full drill fill the actual production volume?

No. Use a bounded file image mounted separately, and check free space on its backing filesystem first. A sparse image still consumes real storage as data is written.

Does deleting the filler file guarantee application recovery?

No. Confirm that space was released, then repeat open, write, fsync and read-back checks. Real services also need checks for read-only states, failed queues and retry behavior.

Dedicated AMD EPYC 7543P server, from $469/month

Configure an HttpNode Dedicated Server View HttpNode AMD rental plans and pricing

HttpNode Dedicated Servers, exclusively yours

Before configuring, check memory, storage, and network requirements. After delivery, view the server credentials in the console.