Netlify Function Timeout after 10 seconds when published

Hi Netlify Community!

I’m trying to make a query to Firebase firestore with in a Netlify function which works perfectly fine when developing locally in Netlify dev, but when published I’m seeing the error:

2020-07-05T16:37:05.769Z 2ed6bae0-3702-441a-97b3-ad7cece3e9de Task timed out after 10.01 seconds .

What’s really weird is that I can see the output being returned correctly in the logs, it’s just the callback doesn’t complete correctly. My full code can be found on github here- https://github.com/chiubaca/jottivity/blob/journals-crud/functions/get-journals.ts

Hope someone can assists! :sob::pray:

1 Like

Hi, @chiubaca, to be clear our support team doesn’t troubleshoot custom code (as a rule - never say never). So, we won’t be digging into the source code but other community members might.

With that said, I can explain the general case which is the most common root cause.

The cause of this is most often that some network connection isn’t being closed. The network connection being left open runs in the process itself being left running.

This often doesn’t cause issues in local testing but does in the deployed lambda function as it is required to exit in 10 seconds or less.

This is often resolved by changing the function code to include calls to close “the connection”. As far as what “the connection” actually is, it is typically a connection to an API or database.

To summarize, please check the code to confirm that you are closing all connections before returning. If that doesn’t resolve the issue or if there are other questions about this, please let us know.

Hi Luke, thanks for your reply,

I just need to figure out what “closing the connection” means in the context of firebase/ firestore. I’ve read through the docs a few times now and I believe I’m simply retrieving a “snapshot” of the data once using .get(). I cant seem to find any sort of methods which “close” the connection , no difference from this code snippet - snippets-node/index.js at 50df79b288b824b08e7e17c97415aa35c55d114f · firebase/snippets-node · GitHub . I will try to reach out to firebase support to see if i’ve missed anything.

UPDATE:
After troubleshooting with some friendly folks over on a Firebase slack channel, this issue is caused when attempting to verify a JWT using the firebase admin SDK. I’ve submitted the full details of this issue over on github here.

thanks for posting a link to that issue, @chiubaca! Seems like you are working with the firebase folks to figure out a solution - please do post it here when you find it so that others can learn from you. many thanks!

@perry Yes of course. Finally got to bottom of the issue!

To close the connection cleanly you have to call admin.app().delete(). Usually this is not necessary but seems to be important in the context of a Netlify function. Hope this help anybody else that stumbles across this.

1 Like

why is netllify full of dumb problems like this

Hey there, @tia :wave:

Hillary from the Support team here. Sorry to hear you are encountering obstacles deploying your project. I imagine that this must be frustrating. Unfortunately, we can’t help you work towards a solution without more information about your site and the obstacle you are encountering. Can you please share a link to your Netlify site as well as a description of the error you are encountering?

I have this website b6ce2df3-b78a-4d99-8ae9-b39e44062672

I need to add timeout to more than 25 , something like 60 sec if possible

Hi @BrinisGulf we can’t do anything about 26s. This is a restriction set by AWS Lambda. Would you like me to bump you to 26s?

yes plz make it 26 sec if you can !

Hi there! we can definitely bump you up to 26 seconds, but you’ll need to be on the Pro tier for us to make that change - that’s a requirement that applies to everyone who wants a bigger timeout. You can upgrade to Pro easily through the Netlify UI dashboard.

If you let us know when you have upgraded, we can change the settings for you!

make sense , when I use express is it the same ?

I’m not sure I understand what you mean by express. Can you clarify?

I mean nodejs express package in place of normal lambda function
by using module.exports.handler = serverless(app);

Hi @BrinisGulf This workflow isn’t typical, please reference this: How to run Express.js apps with Netlify Functions

Could you bump our site e0c3dccf-54d1-4d5d-95b5-93580a90cc49 to 26s too please

Hi, thanks for reaching out! I’ve updated this for you! Please re-deploy to see this in effect.

Thanks Sam. We are seeing really large latency when using external API’s (specifically filemail.com). We don’t get that latency when using postman or localhost, we get a return within milliseconds. On Netlify this is above 10 seconds. Any help would be much appreciated.