Function timeout issue

Hi Netlify Support teams.
I have built a webapp by nextjs.
I’m running into an issue while waiting for an API response.
It seems that if the API response time exceeds 10 seconds, a 502 error will be raised.

However, when I run the app on the localhost, it still works fine even if the response time exceeds 10 seconds.

Is this the same issue as the one previously mentioned?

BTW, the API I used is also openAI’s API but I runing the API service at GCP.

my site name: darling-gumption-95e739

When running a function using Netlify CLI, the same 10 second limit applies and will throw the same error as it does in production.

Is the API made from a Netlify function or the the path /api/* proxied to GCP? If it is proxied, then the response is not returned from Netlify (Netlify will return whatever is returned from the proxy endpoint.)

Thank you for the quick reply.

The API is made from /api/* proxied to GCP, I did not use Netlify function.

Do you mean that the 10-second limit would not apply to requests made to endpoints under the /api/* path?

Exactly. The 10 second limit only applies to Netlify functions.

Proxy rewrites have a timeout is 30 seconds (which is a fairly long time in terms of web requests) as mentioned here. But I doubt this is the issue.

The 502 error is likely coming from the GCP endpoint, Netlify is simply passing it through to the Axios call.

1 Like

Thanks again!

I just want to confirm that I understand correctly. I have created a file called ‘photographic.ts’ under the ‘/pages/api/’ folder, and in ‘photographic.ts’, I’m calling the real API that I have implemented in GCP. Does above work call “Proxy rewrites”?

Also, I have tested the API implemented from GCP on Postman and it works normally.
Does that mean the timeout of Proxy rewrites in nextjs is not 30 seconds?
Usually, the API takes 10-20 seconds to respond.

Thanks for the extra details. What you have described as I understand Next.js on Netlify is yes this is a function, not a rewrite/proxy.

This would mean the 10 second limit applies.

There is clearly a discrepancy between this test and the real-world deployed function. Is there perhaps an environment variable (e.g. API key) that is missing from the deploy? Have you tried adding logging to the function to see what is returned from the call or if the call is even made?

I am not a Next.js expert by any stretch of the imagination so I can’t guide you toward any specifics.

Thaks again.

Let me confirm again: Do you mean that Next.js API routes would have the same restrictions as Netlify functions? like this one said Netlify serverless functions vs Next.js API Routes?

If so, how to set a higher limitation for my project?

Yes.

A Netlify Support Engineer can do that for you.

However as I said earlier, I am not sure time is necessarily the cause of failure.

Hi there, I am experiencing the same issue, have you resolved it? if so, how do you do that?

As is mentioned in the post before yours @Jerenyaoyelu, only a Netlify staff member can increase the function execution limit.

which means there is no approach for us to overcome this limit?

No, there is nothing you, as a user, can do other than politely ask for an increase in time.
See Custom Deployment Options for more information.

Hi @Jerenyaoyelu,

Could you provide us with the site name (such as sitename.netlify.app) of the site you want to increase the function timeout?

hi @Melvin, pieces-sam.netlify.app I am in the free plan.

Hi @Jerenyaoyelu,

In order to increase the functions timeout limit for the site, the account will need to be on the Pro Team plan (or above).

If you upgrade to the Pro Team plan or above, please let us know and we’ll be able to increase the Functions timeout limit to 26 seconds (max time).