FrontierJS
← The journey

Files that outlived their rows, and a backup that rotated itself away

[Your take — two or three sentences, in your voice. What was this week like? What surprised you, or what would you do differently?]

The week in numbers

What broke

Files that outlived their rows. When you save a record with a file, the file is written first and the database row second. If the database then refuses the row, because of a duplicate value or a failed check, nothing removed the file. It sat in storage with no row naming it. Worse, a refused update left the old file queued for deletion, so the next update of that model deleted a file the row still held. Inside a transaction that rolled back, an update deleted its old file at once, and the rollback then restored a row pointing at nothing. We moved all cleanup to the moment a write settles: a refused write deletes what it stored, and a successful one deletes the old file only when it commits. The new tests failed before the fix, leaving two, four and five stray files in the three transaction cases. A related fix landed the same week: setting a file column to null used to leave the old file behind, while replacing it deleted the old one.

A backup that could rotate itself away. Before an app's database migrates at boot, the host copies the database and keeps only the newest few copies. Picture migration 2 committing and migration 3 failing. The app crashes, restarts, and copies again, on every boot. After a few restarts the newest copies are all of a half-migrated database, and the one clean copy from before migration 2 has rotated out. We found it by reading the code, not from a lost database. Now each copy is integrity-checked as it is made, a bad copy stops the boot, and rotation always keeps the oldest copy from the failing run. A test replays the crash loop to prove it.

Two writers, one proxy config. The deploy command and the agent on each server both edit the reverse proxy's route list: read it, change it, write it back. If one wrote between the other's read and write, the second write silently undid the first, and its routes vanished. We made every edit carry the config's version tag, so the proxy refuses a stale write and the writer reads again. Then our own race test, which runs against real Docker and a real proxy, failed in four of six runs. Retries ran out against a writer landing routes eight milliseconds away, and the proxy resets connections whenever it reloads its config. The fix was ten attempts with a random pause between them, so the two writers fall out of step, and resending only the calls that are safe to repeat. Six more runs passed 79 of 79 checks.

And an honest one: several of the issues we closed this week were closed as "does not reproduce". Many were test drives that failed because another process on the same machine held a port or a database, which comes from running many agents side by side, not from a bug in the code.

A call we made

How long should a new release get to answer its health check before we call it failed? It was fixed in code, and it differed by deploy path: 20 seconds on one, 30 on others. But a database migration runs at boot, inside that wait. A migration that took longer than the wait was killed halfway on every release. We ruled that the wait belongs to the app: a healthTimeout setting, 30 seconds by default, between 5 and 600, and every deploy path waits that same budget. We turned down a larger fixed wait, because it slows every crash-looping release's rollback. We also turned down "wait while the container is still running", because a hung release would hold the outage open for the whole cap. If owners turn out to guess the number wrong, we will reopen it as "0 means wait while it runs".

[Optional: a sentence on why that one mattered to you.]

Next week

[Your words: one or two things you want to get done.]