prisma: `ConnectionError(Timed out during query execution.)` error when using `Promise.all` for SQLite

Bug description

Just like the title explains, when I use Promise.all to delete (in my case), it throws timed out error.

Never had the same issue with other db such as postgres and mysql. But for sqlite, i am getting this issue.

Is there any workaround or legit solution that I am not aware of for this error?

How to reproduce

model Category {
  id                          String                      @id @default(cuid())
  description                 String?
  name                        String                      @unique
  slug                        String                      @unique
  // *************** RELATIONS *****************
  subcategories               Category[]                  @relation("SuperCategoriesSubCategories", references: [id])
  supercategories             Category[]                  @relation("SuperCategoriesSubCategories", references: [id])
  // *******************************************
  createdAt                   DateTime                    @default(now())
  updatedAt                   DateTime                    @default(now())
  deletedAt                   DateTime?
}
// For front
Promise.all([
  ...send multiple delete request
])
// For backend
prisma.category.delete({
      where: {
        id,
      }
})

Expected behavior

Delete all passed categories

Prisma information

Environment & setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version

3.9.2

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 10
  • Comments: 19 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Same here prisma 4.16.1 with sqlite as driver.

Same here prisma 4.16.1 with sqlite as driver.

@gengjiawen did you end up resolving this?

Nope, I changed db driver to mysql, problem goes away.

I found out, after reproducing this error with concurrent queries in https://github.com/prisma/prisma/pull/22723

That ?connection_limit=1 to the url made this error disappear -> The queries were failing and are successful with the added parameter.

Example

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "sqlite"
  url      = "file:./dev.db?connection_limit=1"
}

If you try that, let us know if that works for you, or not, we’re curious to hear from you 🙌🏼

In case it’s helpful to anyone affected by this:

A workaround until the issue is fixed appears to be enabling WAL in SQLite and appending ?connection_limit=1 to the connection string in schema.prisma. See https://github.com/prisma/prisma/issues/10403#issuecomment-1500770484 for details.

I can confirm this issue exists when invoking a delete() procedure in express and elysia js

Hi, I have the same problem with sqlite/prisma and express. I expose my update procedure through a router in express. When called in the same time for different record, prisma and sqlite throw the error.

For now the only thing that mitigate the problem it been put the route in syncronic mode trought a middleware but in this way I lost the performace of node and express.

5.2.0 still getting the same error with sqlite