Logical-log header published before durable write
The logical log advances its in-memory header before the matching on-disk header write is durable. A fault-injection test drives a header upgrade whose write fails and observes the in-memory header already advanced past what survived on disk — a crash at that point could recover to a header the storage never durably held.
Prerequisites
The logical log keeps an in-memory header (its authoritative version/state) and a matching
on-disk header. On a header upgrade the writer updates the in-memory header and issues the
on-disk header write (write_header, logical_log.rs). The durability contract:
header upgrade ordering that must hold:
1. issue the on-disk header write
2. wait for its completion to confirm DURABLE
3. only THEN publish the in-memory header as authoritativeIf the in-memory header is published before the durable write confirms — and a write failure is ignored — a crash between publish and durable leaves the published header ahead of what storage holds.
The bug
On the header-upgrade path (write_header), the in-memory header is advanced/published before
the on-disk header write is confirmed durable, and a write-completion failure is not propagated:
publish in-memory header = version N (authoritative)
issue on-disk header write ... FAILS
on-disk header = version N-1
crash here -> recovery trusts header N, which was never durably writtenReproduction
A fault-injection test drives a header upgrade whose on-disk write is injected to fail, and
observes the in-memory header already advanced past the durable header. The code under test —
write_header in logical_log.rs — is the function being exercised.
Concrete evidence — captured trace (header-upgrade-failure differential)
in-memory header version: reference None, turso Some(2)The reference model holds the header un-published (None) until the durable write confirms; turso has
already published version 2 (Some(2)) while the on-disk write failed.
Violation card
- Guarantee violated — Logical-Log Header Published Only After Durable: The in-memory logical-log header must not become authoritative before its on-disk write completes. A writer that published its header before issuing the header's durable write, and ignored the write-completion failure, would — under a failed or torn header write — leave the published header ahead of storage.
- Scenario: header upgrade with an injected header-write failure; observe in-memory vs durable header.
- Observed: in-memory header version — expected un-published (
None), actualSome(2). - Expected: in-memory header stays un-published until the durable write confirms.
- Actual: in-memory header advanced to version 2 while the durable write failed.
Source: tursodatabase/turso