Open AjaniBilby opened 9 months ago
When reading the sitemap functions in each route, are they done in parrallel or in squence? Promise.all()
Because if they are bulk dispatched all at once, this would create a connection overflow in Prisma
These two lines sitemaps.ts:150, sitemaps.ts:167, while they are not the direct cause, they will exassurbate the issue, because it means it will attempt to run the sitemap
function for every single route at once. When you attempt to run multiple queries at once in prisma it will attempt to streamline as many as possible. So if I have a connection limit of 10, it will open 10 connections.
Then since I have 207 different routes, it will open only 10 connections and as each query completes it will then schedule another awaiting one on the new open available connection, but the time it gets near to the end it starts timing out because the queries aren't able to be executed on a db connection.
I'll make a PR implementing a rate limiter which reads from a config to limit the promise all execution based on a config varaible if present
With further testing this issue does occur when using
prisma = getClient();
Instead of
if (!global.__db__) {
global.__db__ = getClient();
}
prisma = global.__db__;
Which implies that global variables shared between different files importing it are not actually being shared, and multiple unique instances are being loaded.
The update in the PR does mitigate the issue a bit
Describe the bug For every route the npm task opens a new database connection instead of continuing to use the existing one from other routes.
Almost every single route imports
~/db.server.ts
which is where the database connection is initalizedInterestingly this only occurs when running on the production server, but not in my local environment which is extra odd.