title: Cloud Functions for Firebase interrupted before finishing execution
body: <p>Function is observing <code>proposals/{jobid}/{propid}</code>. When a new proposals is added, and <code>child("isinvitation")</code> is null, the function successfully writes new node to <code>proposals/sent</code>, then adds an increment to proposals child of jobs <code>jobs/${jobid}</code>.</p>
  
  <p>The function is failing when a proposal is removed. <code>userRef.child(jobid).remove()</code> is not triggered also, decrease to proposal child of jobs <code>jobs/${jobid}</code> doesn't happen.</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 isinvitation = event.data.child("isinvitation").val();
      if (!isinvitation) {
          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}`);
                  return collectionRef.once('value').then(snapshot =&gt; {
                          if (snapshot.val() !== null) {
                              const countRef = collectionRef.child("proposals");
                              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>
  
  <blockquote>
    <p>Console log don't show any errors.</p>
  </blockquote>