Error: Connection Closed
Answered
Abhii posted this in #help-forum

AbhiiOP
Hello, I have been building this app it’s working fine on local , it breaks in production on routes like products/[id] and categories/[slug]. In console its shows
Error : Connection closed
https://store-thing.vercel.app/categories
Error : Connection closed
https://store-thing.vercel.app/categories
Answered by B33fb0n3
then it looks like the api that you are using is broken (or at least serverless hosted) and then your connection is broken, because the server was shut downed. If I would be you, I would create a
constants.ts
file that contains some products and then use that. It's much more reliable (or of course your own database)26 Replies

@Abhii Hello, I have been building this app it’s working fine on local , it breaks in production on routes like products/[id] and categories/[slug]. In console its shows
Error : Connection closed
https://store-thing.vercel.app/categories

it sounds like the connection to your database was closed. Make sure you have an open DB connection to make queries

@Abhii solved?

AbhiiOP
I have removed the code where database being used and crashing has stopped, however its still crashing at some pages. I'm still working on those pages to identify whats causing this.
Thank you it was great help , can you please tell how can i fix this as im using mongodb.
Thank you it was great help , can you please tell how can i fix this as im using mongodb.

@Abhii I have removed the code where database being used and crashing has stopped, however its still crashing at some pages. I'm still working on those pages to identify whats causing this.
Thank you it was great help , can you please tell how can i fix this as im using mongodb.

can you share the full error? That would help more 👍

AbhiiOP
the last one , im not getting any error on local so its hard to find whats happening here.
https://github.com/Abhii5496/store-thing , repo if you want to take a look .
https://github.com/Abhii5496/store-thing , repo if you want to take a look .


@Abhii the last one , im not getting any error on local so its hard to find whats happening here.
https://github.com/Abhii5496/store-thing , repo if you want to take a look .

did you set up your .env variables in your production env correctly?

AbhiiOP
yes
when i hard refresh it works

when does this error pop up? When you click something? Hover something? When you interact with something? ...

AbhiiOP
when i navigate to any product detail page (/products/1)

@Abhii when i navigate to any product detail page (/products/1)

can you refresh the current page (should work, as you said) and directly navigate to any other product detail page?

@Abhii well now im getting this

AbhiiOP
ok its working now

@Abhii ok its working now

whats the result of this: https://nextjs-forum.com/post/1326810881891237969#message-1328271310098272296 <--- click

AbhiiOP
its working fine

@Abhii its working fine

but when you refresh the page, wait around 15 seconds and then navigate, it shows the error?

AbhiiOP
thats right

@Abhii thats right

if you remove this fetching part: https://github.com/Abhii5496/store-thing/blob/main/src/app/products/%5Bid%5D/page.js#L80
And also the generateMetaData here: https://github.com/Abhii5496/store-thing/blob/main/src/app/products/%5Bid%5D/page.js#L5-L74
Does the error persists?
And also the generateMetaData here: https://github.com/Abhii5496/store-thing/blob/main/src/app/products/%5Bid%5D/page.js#L5-L74
Does the error persists?

AbhiiOP
no , after removing these two it works well.

@Abhii no , after removing these two it works well.

then it looks like the api that you are using is broken (or at least serverless hosted) and then your connection is broken, because the server was shut downed. If I would be you, I would create a
constants.ts
file that contains some products and then use that. It's much more reliable (or of course your own database)Answer

@Abhii solved?

@B33fb0n3 then it looks like the api that you are using is broken (or at least serverless hosted) and then your connection is broken, because the server was shut downed. If I would be you, I would create a constants.ts file that contains some products and then use that. It's much more reliable (or of course your own database)

AbhiiOP
you are right about the api , i'll go with contatants idea for now. Thank you very much for your help.

sure thing