Skip to content
Back to the playbook

Fixing D1 SQLITE_BUSY errors from concurrent writes

Cloudflare D1Cloudflare Workersrevision 1

Diagnostic tree

  1. In progressD1 write throws SQLITE_BUSYA write against D1 (INSERT/UPDATE/DELETE via `db.prepare(...).run()` or `db.batch(...)`) throws an error containing SQLITE_BUSY or "database is locked".
View the whole map (7 more steps)
  • Check whether two writes are landing at the same moment
  • Retry the write with backoff
  • Check whether one invocation issues many separate write statements in a loop
  • Combine the loop of writes into one db.batch() call
  • Not a write-write collision — escalate
  • Re-run under the same concurrent load
  • Resolved

What to test

D1 write throws SQLITE_BUSY

A write against D1 (INSERT/UPDATE/DELETE via `db.prepare(...).run()` or `db.batch(...)`) throws an error containing SQLITE_BUSY or "database is locked".

What happened?