Sam Morgan
Sam Morgan

Reputation: 201

Vercel: Task timed out after 10.01 seconds

I recently deployed a Next.js application for a software engineering boot camp. I am using Vercel for hosting the web app. The problem I am having has been spoken about on the internet before. However, I couldn't find much helpful information.

When I look at the real-time logs for my application from my Vercel dashboard, a 504 error gets thrown for multiple API routes I have created. I am aware that Vercel places restrictions on requests depending on the hosting plan someone subscribes to. However, I can't help but wonder if I have overlooked an important step when deploying my application.

When deploying my application, I did the following things:

  1. Connected a session store to my MongoDB database.
  2. Created a password-protected MongoDB Atlas account (credentials are environment variables).
  3. White-listed all IP addresses so that any user can interact with their portion of the database.

I would appreciate help finding out if these errors are my fault and if there is anything I can do about them or if they are solely caused by the restrictions of the "Hobby" plan.

Thank you very much in advance, -Sam

Screen Shot: enter image description here

Upvotes: 2

Views: 4351

Answers (4)

vitxr
vitxr

Reputation: 364

I'm using mongodb hosted at cloud.mongodb.com and by default the unique allowed ip address is your local machine ip.

in cloud.mongodb.com panel, go to networks tab

atlas panel

click in the ADD IP ADDRESS button and add your vercel dedicated project ip if you have one or you can allow all ip addresses using 0.0.0.0/0

Vercel uses dynamic ips and you can't have a dedicated one in the hobby plan

Due to the nature of the Vercel infrastructure, all outbound function requests come from a range of highly dynamic IP addresses and a fixed IP range cannot be given.

You can explore secure-compute which allow you get a dedicated IP (and some additional secure resources), but it is an enterprise plan though.

Upvotes: 1

0xJayden
0xJayden

Reputation: 131

You need to integrate MongoDB in your project on Vercel.

Go to your project settings in Vercel and go to the Integrations tab. Click the Browse Marketplace button and find MongoDb. Click Add Integration button and follow the instructions.

Hope this helps... I know this was asked quite a while ago.

Upvotes: 6

assellalou
assellalou

Reputation: 29

I had a similar issue, turned out, it was just the fact that I did not add the vercel ip addr to the network access page on mongodb so momgodb was blocking vercel from accessing data.

Upvotes: 2

Ramakay
Ramakay

Reputation: 3135

You have to troubleshoot the issue by doing the following

  1. Eliminate the NextJS app out of the equation - Using postman https://www.postman.com/downloads/ - Confirm the output of your API, what is the time the API takes? Given function invocation has a limit, you need to optimize the API to meet the threshold.
  2. If the API times are fine and resolution occurs outside of your app, the next step is to troubleshoot the API route, remove the DB parts and just echo back a success message and check the function invocation time.

If #2 turns out to be the issue, reach out to vercel support - Another option could be hosting it outside and whitelisting the cross domain API ask from your application.

Upvotes: -1

Related Questions