// libSQL error reference

replica out of date: stale reads from a failing replica

Sync from the primary is failing, so db.sync() throws the underlying error and reads keep returning the last frames the replica applied.

Erreur
replica out of date
Catégorie
Replicas and consistency
Message d'erreur
replica out of date with the primary

Ce que cela signifie

An embedded replica only advances when a sync succeeds. When db.sync() fails, the replica stops taking new frames and reads keep answering from the last state that was applied: stale reads that fail no check of their own. The failure itself surfaces through sync() as whatever the underlying client error is, for example a connection failure or SERVER_ERROR with an HTTP status when the token is rejected. Turso's docs describe the flow: reads run locally from the file, and writes are sent to the cloud primary and then reflected back to the replica, so a sync gap sits between your writes and what your reads return.

Causes courantes

  • The network path to the primary dropped, and every sync since has failed.
  • The auth token used for sync expired or was invalidated, so the sync request answers 401.
  • Syncs run rarely (no syncInterval and no manual calls), so reads lag behind the primary without any failure.

Find the cause

Run `db.sync()` and read the thrown error: a socket or DNS failure points at the network, `SERVER_ERROR` with 401 at the token, `SQLITE_BUSY` at a local writer holding the replica file. If sync succeeds but reads still look old, write a known value through the primary and read it back through the replica: the difference is the sync gap.

Comment le corriger

  1. Call sync() and read the error it throws; it names the real failure:

    await db.sync();  // throws the underlying connect, HTTP or auth error
  2. For 401-shaped failures, mint a fresh token and update the client config:

    turso db tokens create mydb
  3. When a decision needs current data, read that one query through the remote URL instead of the replica:

    const primary = createClient({ url: 'libsql://mydb-myorg.turso.io', authToken });
    const row = await primary.execute('SELECT ...');

Other ways to handle it

Reads that must always be current can go through the remote libsql:// URL; keep the replica for the fast local reads that tolerate a sync gap.

Reproduisez-le en toute sécurité

Local and honest: run `turso dev --db-file scratch.db`, point an embedded replica at it (a `file:` URL with `syncUrl` set to the dev server), sync once, then kill the dev server and call `db.sync()` again; it fails with a connection error while reads keep working. Restart the dev server and sync again to watch the replica catch up.

Questions

What happens to reads when an embedded replica sync fails?

They keep working locally and answer from the last frames that were applied, so nothing throws on read. The staleness is only visible by comparison, which is why the failing sync() call is the signal to watch.

Does @libsql/client sync automatically?

Yes when you configure syncInterval; otherwise the replica syncs when your code calls db.sync(). A long interval or a missing call means reads lag by design, and failures surface wherever sync runs.

Erreurs liées

Le code et le texte du message sont issus de libSQL / Turso documentation. Parcourir la liste complète libSQL error list ou Rechercher toutes les erreurs de base de données.

// moins d'erreurs, corrections plus rapides

Work on libSQL in SQLly

A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for libSQL and the other databases you use.

Texte et données de cette page : CC BY 4.0, en citant SQLly (sqlly.app). Code et extraits SQL : MIT. Détails de la licence Le texte des messages d’erreur cité appartient à l’éditeur de la base de données.