SQLite times out during query execution when using Promise.all() / concurrent
See original GitHub issueBug description
I’m attempting to await multiple queries at once using Promise.all(), something which works fine on MySQL, however on SQLite this gives the following error
touch(): Error:
Invalid `prisma.session.update()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: ConnectionError(Timed out during query execution.) })
Error:
Invalid `prisma.session.update()` invocation:
Error occurred during query execution:
ConnectorError(ConnectorError { user_facing_error: None, kind: ConnectionError(Timed out during query execution.) })
at cb (xxx\node_modules\@prisma\client\runtime\index.js:36956:17)
I’m hoping to use Promise.all() to execute and await multiple queries at once as performance optimization. I have also found the library prisma-session-store to use a similar pattern thus also resulting in this error.
It is also worth mentioning the error isn’t always thrown. It seems fairly inconsistent when the error is and isn’t thrown, however most of the time it is.
How to reproduce
- Pass multiple concurrent queries into Promise.all()
- Error is usually thrown
Expected behavior
The queries complete concurrently and the Promise.all() resolves. This is the behavior in MySQL.
Prisma information
Example:
await Promise.all([
database.tableOne.update({ ...your query... }),
database.tableTwo.update({ ...your query... })
]);
Environment & setup
- OS: Windows
- Database: SQLite
- Node.js version: v14.17.1
Prisma Version
prisma : 2.30.3
@prisma/client : 3.1.1
Current platform : windows
Query Engine (Binary) : query-engine b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at node_modules\@quixo3\prisma-session-store\node_modules\@prisma\engines\query-engine-windows.exe)
Migration Engine : migration-engine-cli b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at node_modules\@quixo3\prisma-session-store\node_modules\@prisma\engines\migration-engine-windows.exe)
Introspection Engine : introspection-core b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at node_modules\@quixo3\prisma-session-store\node_modules\@prisma\engines\introspection-engine-windows.exe)
Format Binary : prisma-fmt b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at node_modules\@quixo3\prisma-session-store\node_modules\@prisma\engines\prisma-fmt-windows.exe)
Default Engines Hash : b8c35d44de987a9691890b3ddf3e2e7effb9bf20
Studio : 0.423.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:9
- Comments:11 (3 by maintainers)
Top Results From Across the Web
sqlite timeout error multiple queries run one after another
I've got a self contained project that runs with NextJS 12 using the API for routing and client side for updates. I consistently...
Read more >Unable to execute sqlite db query asynchronously in react ...
asynchronous means doing one after another, and synchronous means doing all together, right!. I want to execute my first query and everything ...
Read more >Connection management (Guide) - Prisma
A connection pool timeout can occur if: Many users are accessing your app simultaneously; You send a large number of queries in parallel...
Read more >872 check-ins using file src/printf.c version e99ee974 - SQLite
DB's distinct-per-VFS post-open() step to accept either a batch of SQL or a callback function. Increase OPFS's busy timeout to 10s. (check-in: 9feefe25 ......
Read more >Asynchronous Programming in JS - e-Lite
Asynchronous Programming. • Database Access with SQLite. • Promises ... filter() creates a new array with all elements for which the callback returns...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m seeing the same issue using prisma with sqlite, unrelated to seeding or Promise.all();
When executing 5 updates in parallel (not even on the same records, just the same table), it seems to occur with just one of the records. In my case I’m running the updates in parallel by using forEach over a set of records I need to update, but I’m going to work around it by using a for loop with an await inside.
I’m not using
Promise.all
but I have a CLI app that runsn
worker functions concurrently and I’ve been fighting this problem all night.I’ve written a function serializer and wrapped all prisma calls with it and it worked. But then I read the
?connection_limit=1
trick which worked without my serialization stuff, which is better.I’ve started using Prisma a month ago and I feel like SQLite support is in general very poor. It’s very demotivating.
Extra note: Ensure that you don’t have zombie node.js process in background accessing to the database or the
connection_limit
trick will not work 😅 I’m saying this because after hours of trying every possible fix and configuration, the final problem was that I accidently had 3 zombie nodejs processes in the background touching the db.