Error: Connection closed in production
Answered
Mini Satin posted this in #help-forum
Mini SatinOP
My app is randomly crashing and throwing this error. It's totally random and i've got no better logs into vercel or in the browser...
Locally i don't have any problem.
I cannot ship the project as it's randomly ruining the user experience, i'm on this since days... 😦
The crash is not consistent and i cannot tell if there's something wrong with my code or if it's vercel...
It's the same issue as here : https://github.com/vercel/next.js/issues/52824
and here : https://github.com/vercel/next.js/issues/49205
and here : https://nextjs-forum.com/post/1130833468864086027
Some people says it's not fixed, some say it's fixed... I'm really having a headache here...
What should i do to at least have a better stacktrace ?
Source map on the screen below are enabled
Locally i don't have any problem.
I cannot ship the project as it's randomly ruining the user experience, i'm on this since days... 😦
The crash is not consistent and i cannot tell if there's something wrong with my code or if it's vercel...
It's the same issue as here : https://github.com/vercel/next.js/issues/52824
and here : https://github.com/vercel/next.js/issues/49205
and here : https://nextjs-forum.com/post/1130833468864086027
Some people says it's not fixed, some say it's fixed... I'm really having a headache here...
What should i do to at least have a better stacktrace ?
Source map on the screen below are enabled
Answered by Mini Satin
Sometimes i forgotten to call the db connection function when i was querying it.
So in some edge cases the connection was not cached and this resulted to database TTL, crashing the page.
So in some edge cases the connection was not cached and this resulted to database TTL, crashing the page.
5 Replies
Mini SatinOP
Sometimes i forgotten to call the db connection function when i was querying it.
So in some edge cases the connection was not cached and this resulted to database TTL, crashing the page.
So in some edge cases the connection was not cached and this resulted to database TTL, crashing the page.
Answer
Spectacled Caiman
hey @Mini Satin , did you fix the problem?
I am facing the same thing
Mini SatinOP
Yes as i said above, you got to ensure that you're DB connection has been cached before each request to your DB. Beware as the problem could be another thing in your project, the error itself is not relevant and could be triggered on any async behavior that crashes your app.
I have been able to expose the error in local env by adding a middleware that was doing console.log("hello") on few pages. Well don't ask me how it works, NextJS have a strange range of caveats.
I have been able to expose the error in local env by adding a middleware that was doing console.log("hello") on few pages. Well don't ask me how it works, NextJS have a strange range of caveats.
Ichneumonid wasp
Could you maybe please point me out what i have to do, to get rid of the bug. Im using prisma and i think that the db connection gets closed after a db call was made by the parent sucessfully.
i did this basicly https://nextjs.org/docs/app/building-your-application/data-fetching/patterns#sequential-data-fetching
and used this recommend approach for the prisma client initialaztion :https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices#solution
I have no clue why i get the same error like you
i did this basicly https://nextjs.org/docs/app/building-your-application/data-fetching/patterns#sequential-data-fetching
and used this recommend approach for the prisma client initialaztion :https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices#solution
I have no clue why i get the same error like you