LibsqlError: SQLITE_BUSY: database is locked

I am getting a LibsqlError: SQLITE_BUSY: database is locked error on my insert function here with LibSQL/Turso as my SQLite driver
export async function putClientGroup(
  clientGroup: ClientGroupRecord,
): Promise<void> {
  const db = await getDB()
  const { id, cvrVersion, clientGroupVersion } = clientGroup
  const insertClientGroupStatementQuery = db
    .insert(replicacheClientGroup)
    .values({
      id,
      cvrVersion,
      clientGroupVersion,
      lastModified: new Date(),
    })
    .onConflictDoUpdate({
      target: replicacheClientGroup.id,
      set: {
        cvrVersion,
        clientGroupVersion,
        lastModified: new Date(),
      },
    })
    .prepare()

  await insertClientGroupStatementQuery.run()
}

This error occurs after refactoring my driver from better-sqlite3 to LibSQL / Turso. My application ran without the error with the relatively same code here. The only difference two differences with the LibSQL / Turso driver is that we await to get the
db
and .run() the query statement.

In both the working better-sqlite3 driver and non-working turso driver, we have this function called from within a db.transaction(). Then pullForChanges calls the function with await putClientGroup(nextClientGroupRecord)
  const {
    nextCVRVersion,
    nextCVR,
    clientChanges,
    lists,
    shares,
    todos,
  } = await db.transaction(async () => pullForChanges(
    clientGroupID,
    baseCVR,
    userID,
    replicacheCookie,
  ))
Was this page helpful?