Clock Drift, Timer Slack, and Stale Leader Leases
Switching from wall clocks to monotonic clocks prevents NTP step bugs, yet bounded leases alone still fail to stop split-brain writes when a paused leader resumes milliseconds after losing consensus.
Many distributed coordination layers renew a 10-second lease on the lock server and allow the holder to serve strongly consistent writes until local monotonic elapsed time hits 9 seconds. The mental model seems airtight: as long as renewal checks precede mutations, two nodes should never write concurrently.
The flaw hides between the expiration check and the remote storage write. Even in Go or Rust binaries free of stop-the-world GC pauses, host page reclamation, hypervisor live migration, or overloaded kernel run queues can freeze a process for several seconds right after its monotonic timer check returned "still valid."
Monotonic clocks are local, not causal
Although CLOCK_MONOTONIC never jumps backward, adjtimex slew adjustments and hypervisor KVM clock steals still separate elapsed rates between nodes. More importantly, time-of-check to time-of-use gaps mean downstream storage engines cannot trust a client's belief about lease validity.
-- Storage rejects any mutation whose fencing epoch trails the highest seen epoch.
UPDATE shard_state
SET payload = $1,
highest_fence_epoch = $2
WHERE shard_id = $3
AND highest_fence_epoch <= $2;
Two rules that hold under pauses
- Have the consensus lock store issue a strictly increasing integer
fence_epochon every lease acquisition. - Require the authoritative storage layer (database conditional update, Raft log check, or object-store ETag/generation condition) to verify
incoming_epoch >= stored_epochon every write.
Timers remain a clean optimization for keeping leader churn rare. Monotonic fencing tokens provide the hard correctness guarantee when timers inevitably slip.