Home
Support Forums

Nextjs deployment experiences 502 errors on initial page load

Hi there,

We have a nextjs app deployed for which ~90% of the pages are static. As such, our main page uses getStaticPaths and getStaticProps with the hope that they would be created at build time and ready to render as soon as they’re deployed.

We are building thousands of these pages at build time and the deployment of the site reports to be successful. While the initial homepage request loads relatively quickly (a few seconds), most other initial page loads fail or, at best, are very slow (> 20 seconds). It does seem to “warm up” and, once it is, the pages are snappy.

After the site is deployed and the homepage has loaded we can see in the network tool prefetch queries executed for links on the page. They are a collection GET requests for paths like $HOST/_next/data/$HASH/path/to/file.json

Most of these (often all) retrievals fail with net::ERR_ABORTED 502 at a duration of ~30 seconds (see screenshot attached).

Site details

I don’t see any errors or helpful diagnosis in the function logs for this site. Please could you provide some guidance on how we might get these pages to be ready to serve immediately after they’re deployed and avoid these errors?

Thanks very much, James

hi James and sorry to be slow to get back to you! We spent some time digging into the failing requests in our internal logs, and what we see is that the assets that return 502s are served by a lambda function - and the ones that return that 502 status are universally taking longer than 30 seconds to being sending a response, which is not possible within our network; the requests are errored with a 502 status at the 30-seconds-with-no-response-started-or-finished mark.

Do you know what the code that generates those json files is doing? If it’s making real-time API calls to another service, perhaps that service is very slow to respond?

Hi @fool, thanks very much for looking in to this.

You comment has helped me realise that we weren’t pre-building all the pages we were hoping to at build time. As such there’s a large balance of pages that are getting built post-deploy which, I believe, is causing too much load for the backend services to deal with.

I’m going to try building the full set of pages and see how that goes.

Thanks again, James