Cloud functions for firebase finished with status: 'timeout' : <p>Function gets executed without errors. I am getting the status</p>

<blockquote>
  <p>Function execution took 60004 ms, finished with status: 'timeout'</p>
</blockquote>

<p>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?</p>

<pre><code>exports.countproposals = functions.database.ref("/proposals/{jobid}/{propid}").onWrite((event) =&gt; {
    const jobid = event.params.jobid;
    const userId = event.params.propid;
    const userRef = admin.database().ref(`users/${userId}/proposals/sent`);
    if (event.data.exists() &amp;&amp; !event.data.previous.exists()) {
        userRef.child(jobid).set({
            timestamp: admin.database.ServerValue.TIMESTAMP
        });
    } else if (!event.data.exists() &amp;&amp; event.data.previous.exists()) {
        userRef.child(jobid).remove();
    }
    const collectionRef = admin.database().ref(`/jobs/${jobid}`);
    const countRef = collectionRef.child("proposals");
    return countRef.transaction(current =&gt; {
        if (event.data.exists() &amp;&amp; !event.data.previous.exists()) {
            return (current || 0) + 1;
        } else if (!event.data.exists() &amp;&amp; event.data.previous.exists()) {
            return (current || 0) - 1;
        }
    });
});
</code></pre>
