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:

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 - https://github.com/firebase/snippets-node/blob/50df79b288b824b08e7e17c97415aa35c55d114f/firestore/main/index.js#L568-L572 . 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