'502 BAD GATEWAY GET / TASK TIMED OUT AFTER 10.01 SECONDS

I am using Next.js and express as front end and back end server. Next.js hosted on the Zeit Now, express app hosted on Heroku. If I go to express app, I can make sure that it's working correctly and its connection to mongodb works fine as well. When I hit index page of Next.js through Zeit, it seems to be hanging on the GET / tasks more than 10 seconds. I am only calling 3 end points just GET methods from index.js of Next.js app. This shouldn't be hanging the whole application.

If I go to my server independently, which only takes less than 3 seconds or so to give back JSON data. I also looked at function tab Zeit provided, but it won't show what exactly serverless function was failing. So it is hard for me to debug this. I also set whitelist all IP from Mongo. So the database should be fine.

If anyone dealt with this before, please let me know.

My site is https://www.yaobaiyang.com

Issue happens unexpectedly, you may or may not see this error

enter image description here

enter image description here



Solution 1:[1]

I had the same problem on my website:

  • Check the limit on your plan https://vercel.com/docs/v2/platform/limits (Especially if you're in free plan, you will have some limits.
  • For the problem was an uncatch error, the lambda crashed and wait the timeout.

Solution 2:[2]

Through more understanding, the problem may appear on Heroku, Heroku's free plan is 1000 dyno hours, which is the usage time in general, and then within the 30-minute time limit, if there is no access, the server will go to sleep. . There may be a delay in reawakening, which usually takes longer than when it was active. If this is the problem, the solution is to use

  1. Similar to pingdom or cronjob, a regular automatic request interface, request my Heroku periodically in less than 30 minutes to keep it awake.

  2. Use a VPS like digital ocean or Vultr that runs 24 hours a day, 365 days a month, and then deploy my Node, Nginx, Http/2, etc.

  3. Upgrade Heroku's plan to cancel the 30-minute sleep

  4. Upgrade Zeit has more timeout.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Hasan Sefa Ozalp
Solution 2 Sam Yao