I’m encountering an issue with my task that is timing out after 10.01 seconds. The error message that I’m receiving is “Task timed out after 10.01 seconds” and “Http failure response for https://m2benergy-v2.netlify.app/.netlify/functions/hello 502 OK”.
I believe that this error is being caused by a variety of issues such as slow internet connectivity, a large amount of data to process, or an issue with the code itself. I’ve tried increasing the timeout limit and adding logging to the code to track the progress of the task, but the issue persists.
Does anyone have any suggestions on how I could further diagnose the issue? I’ve also reached out to technical support for Netlify, but I thought it would be helpful to ask the community as well.
Thank you in advance for any help you can provide.
HI @imad, note that there are some limitations on function execution, with the 10 second execution limit being one of the most critical factors.
If the operations in your functions takes more than 10 seconds to complete you will still experience the function crash.
Thanks for your reply.
Actually the function only gets an empty array from a mongoDB database. I’m not sure if this action can take more then 10 seconds…
The quoted message above could be the reason why it is failing.
My suggestion is to kindly try it out your functions locally on your computer and then time the operations happening to see if the root cause could be from where your MongoDB instance is located or not.
In addition to the above kindly refactor your code to the code below. Looks like your mongodb connection is different from the one from the official documentation.
I replaced my code by the one you provide but I’m still having a timeout on mongoDB connection.
If I return a string inside the function everything is ok, but when I add the part regarding the connection to mongo, It’s still failing with a timeout after 26 seconds.
I’m not sure that I missed something for the connection:
DATABASE URI
DATABASE NAME
COLLECTION
Knowing that when I copy paste the URI on Compass, It’s working fine
Kinldy confirm if the function has stopped crashing after the suggestions.
If your problem has been resolved kindly mark the post as resolved in order to helps others in the future who might experience the same problem.
It’s not solved yet.
I think that I’m going to change the database. It looks like it’s a problem with Mongo…
Do you know any DB which works fine with Netlify functions?