vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.95k stars 26.87k forks source link

Random 500 internal server error in production build on page refresh #10279

Closed abhi12299 closed 4 years ago

abhi12299 commented 4 years ago

Problem: In production build, I get a random 500 server error on production when I refresh a page. It stays there for around 5-10 reloads and then goes away. Client side routing works though. This occurs in my personal website https://iabhishek.dev randomly. On inspection, the following code gives errors randomly (line 290)

Screenshot 2020-01-27 at 1 24 57 PM

Code for my website can be found at https://github.com/abhi12299/website

The following is my code for getInitialProps in / page:

code

The getCookie function:

code

The authenticate function:

code

The getLatestPosts function:

code

timneutkens commented 4 years ago

Not sure exactly, I can't reproduce the issue described.


Please follow the issue template.

https://github.com/zeit/next.js/issues/new/choose

https://github.com/zeit/next.js/issues/new?template=8.Question_about_next.md

# Question about Next.js

GitHub Issues are reserved for Bug reports and Feature requests. The best place to get your question answered is to post it on https://spectrum.chat/next-js.
abhi12299 commented 4 years ago

Hi. If I knew how to reproduce the issue, I would have provided more details. But this happens randomly. Please read the issue description again. It just happens on production. On spectrum, the issue would be left unnoticeable. It's a big problem for me, that's why I raised this issue here.

kodcuserkan commented 4 years ago

Similar here any answers or links please?

abhi12299 commented 4 years ago

@kodcuserkan I got this error for a few days without any knowledge of what happened wrong. But it was fixed without any code change after a couple of days.

hems commented 4 years ago

Hi. If I knew how to reproduce the issue, I would have provided more details. But this happens randomly. Please read the issue description again. It just happens on production. On spectrum, the issue would be left unnoticeable. It's a big problem for me, that's why I raised this issue here.

I get the same error here, app works fine locally but when deployed ( I'm using Heroku as a simple test ) the app loads and yields a 500 on the index page without a stack trace or any other information attached to it.

Exactly on the same place, you get the error

image

hems commented 4 years ago

I'm also using getInitialProps on my Page, also the funny thing is I check the server logs and i cant see the 500 error in the logs.

The error seems to happen without stack trace and without being posted to the console on the client and on the server.

hems commented 4 years ago

Not sure if it's relevant but I'm using webpackChunkName when loading 1 of the files, but that's unrelated i guess cause that file loads perfectly.

Also, i can see the index page behaves differently locally and on the deployed server.

On the deployed version on heroku I get 500 error on the index page but on the client, i don't et that error.

hems commented 4 years ago

Ok so turns out in my case NODE_ENV is being set to "production" even tough Heroku NODE_ENV is set to "staging".

I got to figure out what is messing this up.

abhi12299 commented 4 years ago

@hems Did you find something regarding the issue? It was a real pain for me back then.

hems commented 4 years ago

@hems Did you find something regarding the issue? It was a real pain for me back then.

I installed source maps and also found a weird error because as i said my NODE_ENV was always "production" even on my staging and production environment..

https://github.com/zeit/next-plugins/tree/master/packages/next-source-maps

JClackett commented 4 years ago

Having a similar issue when deploying to Now, client side navigation works fine, but refreshing on certain pages causes a 500, this doesnt happen on heroku, so i assume theres something going on with the Now node environment thats causing this issue, but its hard to find any logs

JClackett commented 4 years ago

After checking some more, i notice that the pages that throw a 500 are the ones that have nested/mulitple HOC's around the page. Im using apollo, so am wrapping pages in the withApollo hoc but then have a few layout HOC's as well sometimes.

export default withApollo(SomePage) // Works fine

export default withApollo(withSideBar(SomeOtherPage)) // 500
abhi12299 commented 4 years ago

@JClackett yup, with multiple HOCs I too had this problem.. maybe it has something to do with my implementation but then again, a lot of people have this problem

erikleon commented 4 years ago

experiencing this same problem and trying to determine if its cloudflare or next.js related but the error is very vague and no way to reproduce locally or on a QA/Staging environment

vasc1 commented 4 years ago

yeap, I'm on this boat too

JClackett commented 4 years ago

I resorted to not using hocs now, bit annoying but it seems to be the cause

bikramtuladhar commented 4 years ago

We recently faced this kind of random 500 internal error, it turned out our API server (laravel) triggered API rate-limiting (60 request per minute). Rate limiting response was not logged as an error which made difficult to track the real issue.

taivmo commented 3 years ago

Hi, maybe this might help ! I create a file name : next.config.js in root folder (next to package.json) then in next.config.js file, I add : module.exports = { trailingSlash: true, } Hope this can help someone!

balazsorban44 commented 2 years ago

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.