You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: Host lease: a stalled or clock-skewed holder silently rejoins after another host took over; skew also blocks hosts far past the 20 s TTL #978
Security-relevant (data integrity: two hosts serving one SQLite database), severity: medium. Found in an adversarial review of #949 (#941).
Runtime revision and environment
origin/main ba9f3204, Node 26.10, macOS; the lease is driven directly with fake clocks and probes via joinHostLease's now/probe options.
What happens
packages/core/src/host-lease.tsjoinHostLease checks for a foreign peer only when joining (other = joining ? peers.find(foreign) : undefined). Afterwards each heartbeat deletes expired rows and upserts its own row. Heartbeat errors are swallowed without a log. Expiry compares the observer's wall clock with a deadline the writer computed from its own clock. Three consequences, all observed:
A stalled holder comes back silently. Host A joins, then stalls longer than the TTL (VM suspend, SIGSTOP, a blocked event loop, 20 s of failed beats). Host B joins legitimately, deleting A's expired row. On A's next beat it re-inserts its row and keeps serving. Observed rows afterwards: [{host:'host-a',…},{host:'host-b',…}], and neither side refused or logged anything.
A joiner whose clock is ahead evicts a live holder. If B's clock is more than the TTL ahead, B deletes A's live row and joins (observed rows: [{host:'host-b',…}]). A then re-inserts, as in (1).
A crashed host whose clock was ahead blocks every other host for the size of the skew. Observed with A's clock one day ahead and its connection closed without close(): B is refused with "If that host is gone, its lease expires within 20 s of its last heartbeat", but the refusal lasts a day, and nothing tells the operator how to clear it.
On macOS, Windows and Linux filesystems missing from the network list, this lease is the only guard against multi-host SQLite.
Minimal reproduction
constclock={a: base,b: base};constA=awaitjoinHostLease(dbA,{table: 't',what: 'store',now: ()=>clock.a,probe: {hostname: ()=>'host-a',bootId: async()=>'boot-a'}});clock.b=base+25_000;// A has not beaten for more than the TTLconstB=awaitjoinHostLease(dbB,{table: 't',what: 'store',now: ()=>clock.b,probe: {hostname: ()=>'host-b',bootId: async()=>'boot-b'}});// joinsclock.a=base+25_000;awaitsleep(SERVER_LEASE.heartbeatMs+300);// A's heartbeat// SELECT host FROM t -> host-a, host-b (both serving)
For (3): A joins with now: () => base + 86_400_000 and its connection is closed without close(). B joins with now: () => base and is refused.
Suggested fix
If a beat finds its own row gone, or a live foreign peer present, treat the lease as lost: fail closed (stop serving), log loudly, and do not re-insert.
Log heartbeat failures.
Judge a peer's liveness by whether its heartbeat_at changes, observed on the observer's monotonic clock, rather than by comparing wall clocks across hosts. Or at least name clock skew in the refusal when a foreign row's expires_at is beyond now + ttl.
Activity
fix: host lease survives clock skew and fails closed; sign-out confir…
One serving process per database: replace the host lease with an OS l…