Vercel Serverless Function has timed out error
Asked Answered
L

4

21

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

Lyonnaise answered 6/7, 2021 at 19:52 Comment(2)
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.Diskson
@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.Lyonnaise
M
29

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.

Masturbation answered 1/8, 2021 at 17:53 Comment(5)
makes total sense, since my API is on Heroku free plan, and it times out once in a whileLyonnaise
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.Photomicrograph
Seems like Netlify is the way to goWowser
useful link to deploy next 13 to AWS: reddit.com/r/nextjs/comments/yps1zh/comment/ivkvqpw/…Janicejanicki
Those are the default timeouts now, but if are in the pro plan, you can extend the limit in your functions up to 5 minutes for execution time: vercel.com/changelog/…Fabre
P
8

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

Plumbum answered 7/9, 2022 at 14:14 Comment(3)
Do you know of any FREE providers with a longer execution timeout?Alight
Definitely depends on the framework, i think you can still use vercel but with slightly different set upPlumbum
The last time i failed with vercel: ML model was too large. Here is freecodecamp article on alternatives freecodecamp.org/news/…Plumbum
E
4

For anyone landing here from Google, you can now configure Vercel Functions to run for up to 5 minutes.

https://vercel.com/changelog/serverless-functions-can-now-run-up-to-5-minutes

Enlist answered 26/10, 2023 at 21:51 Comment(4)
Heyy Lee is this still true?Cribbing
Yes! This is still accurate.Enlist
I switched from netlify to vercel for this.Cribbing
I’ve spent a few days now getting a nextjs 14 app using NextAuth v5 with google as an OAuth provider, a jwt strategy, persisting to mongodb working and when I deploy to production I cannot sign in on the hobby plan because it times out every time. This is really disappointing. I would be happy to pay maybe $5 a month to extend this one call but Vercel has made it impossible to run what I would consider a minimal app on the hobby plan.Waist
B
3

Check if setting region using vercel.json will help.

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

Ballet answered 10/6, 2023 at 10:50 Comment(1)
closest I could get to Iowa (the database location) was Cleveland (the Vercel region). Still no dice.Iodism

© 2022 - 2024 — McMap. All rights reserved.