Build log · week ending 23 November 2026

A clock that stepped back, and a pipe that hung

By Tim

Each week I write up what we built on Noisy Brood: what broke, how we fixed it, and what I learned along the way.

A day count of minus one

When someone leaves our waitlist, we record how many days they were on it. The number comes from the database: the time now, minus the time they joined, divided into days and rounded down.

A test failed once in a while on that. The cause was the server’s clock. A virtual machine’s clock can step back a little when it resyncs, so “now” at leaving can read slightly before the join time. The difference is a hair below zero, rounding down gives -1, and the table has a check constraint that refuses a negative day count. A constraint is a rule the database enforces on every row it stores. In production this would have refused the leave itself: a person pressing the button would have seen an error instead of a confirmation.

Look at the last line of the query. The fix keeps the count at zero or more:

DELETE FROM waitlist WHERE id = ${id}
RETURNING last_mailing AS mailing,
          confirmed_at IS NOT NULL AS confirmed,
          -- Never below nought: a clock stepping back between
          -- joining and leaving would otherwise refuse the leave.
          greatest(0, floor(extract(epoch FROM now() - joined_at) / 86400))::int AS days

The new test sets the join time an hour into the future and checks that leaving succeeds and records zero. I first tried one second, but setup could take longer than that, so the test could pass without the fix. With an hour it fails before the change and passes after.

A test that waited on nothing

Our checks run small stand-in programs, and one of them passes a GitHub answer to jq, a tool that filters JSON. About once in three thousand calls, on a busy Mac, jq sat until its 30 second limit. It was not slow. I sampled it while it hung and it was blocked reading its standard input, which is the channel a program reads text from. Node’s spawnSync sends its input option through a socket, and now and then the reading side never saw the end.

I could not find why the end is missed, and I say so in the pull request. What I could do was stop using that route. The stand-in now writes the answer to a file, hands jq the file name, and deletes it:

const answerFile = "gh/answer." + process.pid + ".json";
writeFileSync(answerFile, answer);
const ran = spawnSync("jq", ["-r", "-c", jq, answerFile], {
  stdio: ["ignore", "pipe", "pipe"],
  encoding: "utf8",
  timeout: limit,
  killSignal: "SIGKILL",
});
rmSync(answerFile);

Before the change I saw four hangs in 33 runs of the suite under load. After it, none in 32 runs.

Why it matters

Leaving the list now works even if the server’s clock adjusts at that moment, and the checks that guard every change fail for real reasons instead of random ones.

Noisy Brood files away the mail that doesn’t need you, so the mail that does can find you. We write up what we build each week because every fix like this one is meant to make that a little more reliable. It isn’t open to everyone yet. If you’d like to hear when it can take you, join the list.

All posts