14

I have a Nuxt.js server side website deployed on Vercel. I've noticed that, on some occasions, I get a 504: GATEWAY_TIMEOUT error, with the code FUNCTION_INVOCATION_TIMEOUT and the message "This Serverless Function has timed out".

Why am I seeing this error?

Serverless function has timed out

Pavel Fedotov
  • 748
  • 1
  • 7
  • 29
Opeyemi Odedeyi
  • 766
  • 1
  • 10
  • 38
  • Ran in to this issue today and I found that hosting a database in Australia and trying to use graphQL with a few hits to the database per request definitely causes the issue every time. – Dejan Vasic Mar 05 '22 at 11:19
  • 1
    @DejanVasic I think I discovered the issue. I found that since I was using heroku on the free tier. The server sleeps after some due to inactivity, that is mostly when the issue arises. I also noticed in another project where the server is always active that I do not have that issue there. – Opeyemi Odedeyi Mar 06 '22 at 12:16

3 Answers3

22

Vercel imposes some limits when using their platform. This includes a serverless function execution timeout, which is basically the amount of time that a serverless function is allowed to process an HTTP request before it must respond.

If you need a longer execution timeout, you can try using Edge functions. They have to return a response in 30 seconds but can stream indefinitely.

Recently, they have silently reduced the serverless function execution timeout from 10s for the hobby plan, 60s for the pro plan and 1000s for the enterprise plan to, respectively, 5s, 15s and 30s. This might be the reason why you're experiencing this error now.

I really didn't like the fact that they lowered these limits without warning their users (I wasn't warned, at least) and giving them time to adjust.

Jan Kaifer
  • 664
  • 4
  • 18
Talendar
  • 1,841
  • 14
  • 23
  • 2
    makes total sense, since my API is on Heroku free plan, and it times out once in a while – Opeyemi Odedeyi Aug 02 '21 at 12:04
  • 3
    I won't be surprised, they did it before (back when the company name was Zeit) when they deprecated API v1 without consulting their customers or giving them much time to upgrade their websites. Migration wasn't even easy and they had to drop using Docker. Many developers complained about having to migrate all of their websites on the planform to keep using their service. – Abdalla Arbab Aug 30 '21 at 11:39
  • 1
    Seems like Netlify is the way to go – Youzef Jun 11 '22 at 06:22
  • useful link to deploy next 13 to AWS: https://www.reddit.com/r/nextjs/comments/yps1zh/comment/ivkvqpw/?utm_source=share&utm_medium=web2x&context=3 – Pencilcheck Jan 20 '23 at 10:58
5

As of 7 September 2022, the Hobby plan on Vercel supports Serverless Function Execution Timeout for 10 seconds. Pro for 60 seconds. Enterprise for 900 seconds. enter image description here

Here is a link to their pricing plans: https://vercel.com/pricing

Pavel Fedotov
  • 748
  • 1
  • 7
  • 29
0

Check if setting region using vercel.json will help.

Deployment regions: https://vercel.com/docs/concepts/edge-network/regions

jsbisht
  • 9,079
  • 7
  • 50
  • 55