Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloud functions for firebase finished with status: 'timeout'

Function gets executed without errors. I am getting the status

Function execution took 60004 ms, finished with status: 'timeout'

I am not sure what the issue is. Everything in my function looks good to me. I also noticed functions sometimes take several seconds to update database and sometimes it is instantly. Is it normal that execution times varies from instantly to couple second? Should execution times be instantly?

exports.countproposals = functions.database.ref("/proposals/{jobid}/{propid}").onWrite((event) => {
    const jobid = event.params.jobid;
    const userId = event.params.propid;
    const userRef = admin.database().ref(`users/${userId}/proposals/sent`);
    if (event.data.exists() && !event.data.previous.exists()) {
        userRef.child(jobid).set({
            timestamp: admin.database.ServerValue.TIMESTAMP
        });
    } else if (!event.data.exists() && event.data.previous.exists()) {
        userRef.child(jobid).remove();
    }
    const collectionRef = admin.database().ref(`/jobs/${jobid}`);
    const countRef = collectionRef.child("proposals");
    return countRef.transaction(current => {
        if (event.data.exists() && !event.data.previous.exists()) {
            return (current || 0) + 1;
        } else if (!event.data.exists() && event.data.previous.exists()) {
            return (current || 0) - 1;
        }
    });
});
like image 710
Diego P Avatar asked Mar 31 '17 21:03

Diego P


People also ask

How long can a cloud function run by default before timing out?

Function execution time is limited by the timeout duration, which you can specify when you deploy a function. By default, a function times out after one minute (60 seconds), but you can extend this period: In Cloud Functions (1st gen), the maximum timeout duration is nine minutes (540 seconds).

How long can a Firebase function run?

Time Limits60 minutes for HTTP functions. 10 minutes for event-driven functions.

How many requests can handle a single cloud function?

By default each Cloud Run container instance can receive up to 80 requests at the same time; you can increase this to a maximum of 1000.


1 Answers

From my experience I would guess that this is (hopefully) a temporary problem with firebase function itself. I get the same warnings/error for a function which yesterday took ~200 milliseconds to execute in average.

like image 155
Haves Avatar answered Sep 19 '22 05:09

Haves