// 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.

Error
replica out of date
Categoría
Replicas and consistency
Mensaje de error
replica out of date with the primary

Qué significa

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.

Causas comunes

  • 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.

Cómo solucionarlo

  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.

Reprodúcelo de forma segura

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.

Preguntas

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.

Errores relacionados

El código y el texto del mensaje son de libSQL / Turso documentation. Explora la lista completa de libSQL error list o buscar cada error de base de datos.

// menos errores, correcciones más rápidas

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.

Texto y datos de esta página: CC BY 4.0, con atribución a SQLly (sqlly.app). Código y fragmentos SQL: MIT. Detalles de la licencia El texto citado de los mensajes de error pertenece a su proveedor de base de datos.