title: Firebase cloud function returning before function is complete
body: <p>I uploaded a cloud function to perform the update operation on multiple places in the database.</p>
  
  <p>When I uploaded it was working fine but suddenly it stopped working and in the HTTP, it just returned <code>{}</code>.</p>
  
  <p>I again looked at my code and found out that now the function is returning itself <code>{}</code>
  before the function reached the end.</p>
  
  <p>I don't know what suddenly happened it broke my whole application.</p>
  
  <pre><code>const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  const serviceAccount = require('./myapp.json');
  admin.initializeApp({
      credential: admin.credential.cert(serviceAccount),
      databaseURL: 'https://myapp-b2365.firebaseio.com'
  });
  
  exports.quarter = functions.https.onRequest((req, res) =&gt; {
       userType1 = admin.database().ref('users/Type1').once('value');
       userType2 = admin.database().ref('users/Type2').once('value');
       userType3 = admin.database().ref('users/Type3').once('value');
       userType4 = admin.database().ref('users/Type4').once('value');
      app_con = admin.database().ref('app_con').once('value');
       Promise.all([userType1, userType2, userType3, userType4, app_con]).then(result =&gt; {
          console.log(0);
          result[0].forEach(action =&gt; {
              action.ref.update({
                  'AverageRating': (action.val().Rating  + action.val().AverageRating )/2,
                  'Rating': 0
              })
          });
           console.log(1);
          result[1].forEach(action =&gt; {
               action.ref.update({
                   'AverageRating': (action.val().Rating  + action.val().AverageRating  )/2,
                   'Rating': 0
               })
           });
          console.log(2);
          result[2].forEach(action =&gt; {
              action.ref.update({
                  'Rating': 0
              })
          });
           console.log(3);
          result[3].forEach(action =&gt; {
              action.ref.update({
                  'Rating': 0
              })
          });
          let q = result[4].val().quarter;
          let y = result[4].val().year;
          if (q === 4) {
              q = 1;
              y = y+1;
          } else {
              q = q+1;
          }
          console.log(4);
          result[4].ref.update({
              'quarter': q,
              'year' : y
          })
         return res.send('Done');
      }).catch(error =&gt; {
          return res.status(500).send(error);
      })
  });
  </code></pre>
  
  <p>Interesting thing is that out of the 4 <code>console.log()</code> i see only seeing </p>
  
  <pre><code>info: User function triggered, starting execution
  info: 0
  info: 1
  info: 2
  info: Execution took 291 ms, user function completed successfully
  </code></pre>
  
  <p>I don't know what is happening and how it is possible??</p>