Post

Fixing Uptime Kuma WAL Backup Starvation Under Concurrent Writes

Fixing Uptime Kuma WAL Backup Starvation Under Concurrent Writes

The recent push updates the Uptime Kuma backup test to reliably detect and prevent WAL backup starvation when multiple concurrent writes occur, a condition that could otherwise cause backup failures and data loss in the homelab.

Root cause of backup starvation

During testing I observed that the Uptime Kuma backup job would miss heartbeats and fail to complete when simultaneous writes inserted large payloads, leaving the WAL file unflushed and causing the backup process to stall.

Test adjustments to reproduce the race

I expanded scripts/ci/uptime-kuma-backup-test.py by adding a large BLOB insertion, a custom CommittingReader class that commits after each backup step, and updated the heartbeat assertions to reflect the expected single heartbeat under concurrent load. The new checks verify that the backup completes despite concurrent writes.

Design change to eliminate starvation

The CommittingReader.backup method now inserts a heartbeat record and calls commit() after each step, ensuring the WAL is flushed promptly and preventing the starvation scenario that previously blocked the backup.

Verification and next steps

With the code merged, the next step is to run the updated test suite in a CI pipeline that simulates concurrent writes and confirm that the backup succeeds, after which the fix can be applied to production deployments.

This post is licensed under CC BY 4.0 by the author.