Next.js Discord

Discord Forum

Error: Connection closed in production

Answered
Mini Satin posted this in #help-forum
Open in Discord
Avatar
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
Image
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.
View full answer

5 Replies

Avatar
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.
Answer
Avatar
Spectacled Caiman
hey @Mini Satin , did you fix the problem?
I am facing the same thing
Avatar
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.
Avatar
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