pgref.dev/sqlite/errors/SQLITE_ABORT_ROLLBACK
SQLITE_ABORT_ROLLBACKWARNINGTier 2 — Caution⚠️ MEDIUM confidence

Statement aborted due to ROLLBACK

Category: TransactionVersions: 3.8.8+

🔴 Production Risk Error

Medium — silent data loss if the abort is not detected and the transaction not retried.

What this means

SQLITE_ABORT_ROLLBACK (516) is an extended result code indicating that a prepared statement was aborted because the transaction it was part of was rolled back. The statement result is invalid and should be discarded.

Why it happens

  1. 1Concurrent thread or connection issued ROLLBACK while a statement was executing.
  2. 2Application logic rolled back the transaction mid-execution.
  3. 3Trigger or ON CONFLICT clause caused an implicit rollback.

How to reproduce

Multithreaded or multi-connection SQLite usage with shared transactions.

trigger — this will ERROR
import sqlite3
conn = sqlite3.connect('test.db', check_same_thread=False)
conn.execute('BEGIN')
conn.execute('CREATE TABLE IF NOT EXISTS t(x)')
conn.execute('INSERT INTO t VALUES(1)')
# From another thread or connection:
conn.execute('ROLLBACK')
# Any pending statement now returns SQLITE_ABORT_ROLLBACK
sqlite3.OperationalError: abort due to ROLLBACK

Fix 1

Why this works

Catch SQLITE_ABORT_ROLLBACK and retry the entire transaction from the beginning.

Fix 2

Why this works

Finalise all statements before calling ROLLBACK.

Fix 3

Why this works

Use connection-per-thread pattern to avoid cross-thread transaction interference.

What not to do

Why it's wrong:

Version notes

Sources

📚 Official docs: https://www.sqlite.org/rescode.html#abort_rollback

🔧 Source ref: sqlite3.h — SQLITE_ABORT_ROLLBACK = 516

📖 Further reading: SQLite transaction control

Confidence assessment

⚠️ MEDIUM confidence

Stable.

See also

📄 Reference pages

SQLite transactions
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →