title: Cloud Functions for Firebase suddenly timing out
body: <p>Suddenly after deploying my functions today some of our functions suddenly always timeout. I see this in the cloud functions console. This seems to happen when nesting and returning promises. Strange thing is this never happened before.</p>
  
  <p>Here's my code.</p>
  
  <pre><code>exports.pushMessageQueue = functions.database.ref('/userPushMessagesQueue/{userId}/{messageId}').onWrite(event =&gt; {
      if (!event.data.exists()) {
          console.log('DOES NOT EXIST!');
          return "not exists";
      }
  
      console.log("EXISTS!");
  
      const userId = event.params['userId'];
      const messageId = event.params['messageId'];
  
      const payload = event.data.val();
  
      return database.ref('devices').orderByChild('user_id').equalTo(userId).once('value', snapshot =&gt; {
          if (!snapshot.exists()) {
              return "no devices found";
          }
  
          const devices = snapshot.val();
  
          const deviceTokens = [];
  
          snapshot.forEach(deviceSnap =&gt; {
              const device = deviceSnap.val();
              deviceTokens.push(device['fcm_key']);
          });
  
          const removeFromQueue = database.ref(`/userPushMessagesQueue/${userId}/${messageId}`);
  
          console.log('then0');
  
          return removeFromQueue.set(null).then(() =&gt; {
              console.log('then1');
              return admin.messaging().sendToDevice(deviceTokens, payload).then(() =&gt; {
                  console.log('then2');
                  return "send";
              });
          }, (error) =&gt; {
              console.log('error1!');
              console.log(error);
          });
      });
  });
  </code></pre>
  
  <p>In the console then0 is logged, not then1 and then2. And that while I receive the push notification and the entry is removed from the queue.</p>
  
  <p>Is there something I am doing wrong?</p>