Skip to content

Stuck, not broken

A hang is worse than a crash: a supervisor restarts a crash and an alert shows it, but a hang looks healthy for ever. In fdyno, an export whose destination no worker could verify stayed IN_PROGRESS for ever, with no error. A review of the background jobs found more cases like it. Each fix gave the job an end state or a way past the item that blocked it.

Safety checks cannot see a hang

Most checks are safety checks: they ask whether something bad can happen, such as a lost write or a stale read. A job that stays IN_PROGRESS for ever breaks none of these rules. A system can pass every safety check by doing nothing. The missing property is liveness: the export ends, the backlog drains, the index goes ACTIVE.

Only a few fdyno jobs had a liveness check, such as the index backfill model. So a reviewer read the durable job state machines for one thing: a state that a real sequence can reach and that nothing ever leaves. The sweep read source only; each finding then needed a reproduction by its owner before a fix.

The fixes follow four rules. The first applies to the process itself; the others to its jobs.

1. Check every dependency at startup

A process that cannot talk to its database should exit, not wait. Before, an fdyno process whose libfdb_c did not speak the cluster's protocol started and answered /readyz with 503 for ever. Nothing restarted it, because it had not failed.

Now startup must get one FoundationDB read version within 10 s, or the process exits 1. The error names a protocol mismatch that the client saw (configuration, 05c539b8). A cluster that is down at start makes the process exit, and the supervisor restarts it. That release also had a startup override for an unreachable cluster. Current releases require a read version at startup.

2. Give every wait a deadline that ends in a visible state

An export that never ends. On current cluster versions, an export pins its destination when it is accepted (export to S3). A worker that cannot verify that destination skips the job, because a peer may still see it. When no worker can, every pass skips the job, and DescribeExport shows IN_PROGRESS for ever.

Fix (505b1c62): the first failed verification is recorded. A worker that lists the bucket may verify the destination in the next 24 hours. If none does, the next failed check starts failure handling. The job ends FAILED with ExportFailed. It ends with PublishOutcomeUnknown instead when fdyno cannot rule out a published summary. A success clears the record.

Workers measure the 24 hours with their own clocks, so a clock difference between processes moves the limit by that difference. During a rolling upgrade, a process from before the fix drops the recorded start, so the 24 hours can start again. An older MANIFEST job with a tracked summary location enters cleanup and stays IN_PROGRESS until cleanup decides its final code. A bucket that no process lists still leaves the export IN_PROGRESS.

A lease written by a clock far ahead. A peer takes a lease when the stored expiry has passed by its own clock. If the holder's clock ran an hour ahead and the holder died, every peer waited an hour. Fix (73d1e7e3): a process may take another owner's lease when the expiry is too far ahead. "Too far" is more than the lease lifetime plus 5 minutes past the process's own clock. The process must first see the same stored value, unchanged, for one full lifetime on its monotonic clock. The value must still be implausible at the read that takes it.

Each renewal by a holder of this release writes a strictly larger expiry. So a holder that renews within the reader's lifetime always changes the value and is not taken this way.

A binary from before the fix can repeat its value during an upgrade. That ends in a fenced handover. Every lease user is fenced, so a holder that was only slow has its next write refused. There is no deadline promise. The deployment page gives the shortest wait: 151 seconds for a worker lease at a 1-second interval, and 3 minutes for a job lease.

3. Give every loop a way past the item it fails on

A cursor that stops on its own failure. Backup garbage collection stores a cursor so the next pass continues. On an error, it stored the name before the failing one. So the next pass failed at the same name first and stored nothing, and no later name was examined again. Fix (4925e64b): store the failing name, so the next pass starts after it; the name is tried again when the rotation wraps.

One row that fails holds every row behind it. The TTL drain deletes a batch of expired rows in one transaction. If one row's delete fails every time, the batch clears nothing, and the next pass starts at the same entry. The review found no reachable error that does this today; an item that does not decode would be enough. Fix (ec243c87): halve the batch; at one entry, read past it for the rest of the pass. The skip writes nothing, so a later pass tries the entry again. FoundationDB errors, throttles and lost leases are not skipped. At most 16 entries per range of a table are skipped per pass, each counted in fdyno_ttl_drain_entries_skipped_total.

One hot row holds the backfill. The TTL backfill retries a conflicting page with half the rows, down to a floor of 16. A row in those 16 that is written during every attempt stopped the cursor for good. Fix (702e092b): the floor is one row, and a one-row page whose attempts were all retried is skipped and counted in fdyno_ttl_backfill_rows_skipped_total. The skip keeps the backfill from completing, so a later wrap reads the row again.

A fixed order starves the end of the list. The TTL drain used to visit tables in name order. If the first table spent the whole pass budget, the tables after it got nothing. The former delete cap made this easy to show; a time budget can end a pass in the same way. The TTL backfill had the same problem.

Table A gets 500 new expired rows before every pass and table B has 40. The cap is 500 deletes per pass. With a fixed order, A takes the whole cap in every pass and B keeps its 40 rows. With a start that rotates, the second pass starts after A, B's batch deletes its 40 rows, and A gets the other 460.

Fix: both now rotate their start and wrap. The drain remembers, per TTL range, the last table whose batch it attempted or whose bucket probe failed or found nothing (259b4c49). The backfill starts after the table whose page it last attempted without a throttle (f98082b6). The position is in memory and only picks the order; it never decides what is eligible.

4. End a job that cannot succeed, in the same transaction

A staged restore could stay READY while another table held its target name, and fail on every pass. If the name became free, a pass could publish that old backup under it. A v1 restore with a missing chunk marked the job FAILED but left its target CREATING and holding the name. An item with a key type the target does not declare was published as is. A backup of a correct table cannot hold such an item, but an altered or already-corrupt source can.

Both now end FAILED in one transaction; the v1 restore also removes its CREATING target if it is still this job's target (84b78689, 8a40c3df). A target that an older process left CREATING is not repaired. An error that can succeed later, such as a FoundationDB error, a throttle or a lost lease, is still retried.

Apart from the late restore publication and the key of the wrong type, none of these lost data or returned a wrong answer. Each would have left an operator with a job that never ends or a backlog that only grows.

What is still open

A clock far ahead still blocks records that carry the writer's time. These have documented exits and no fixes (deployment page):

  • PITR history: turn point-in-time recovery off and on, which deletes the restore window.
  • Stream records: disable the stream.
  • Transaction tokens: use a new token.

A cluster-version registration left by such a clock has an operator command, remove-registration, not an automatic exit. A clock ahead by more than one minute is outside the clock contract.

What to do with this

Prefer a crash to a hang. Check every dependency at startup and exit if it does not answer within a fixed time. Give every wait a deadline that ends in a state an operator can see, such as FAILED. Give every loop a way past the item it fails on, and rotate where it starts so a full first item cannot starve the rest. Then review each job state machine with one question: which state can a real sequence reach that nothing ever leaves?