title: Cloud Function Bug or error in my code : www.googleapis.com network timeout. Please try again
body: <p>I created a function to send notifications via firebase and I get this error:</p>
  
  <pre><code>Error fetching user data (a0ZdYX3IgCbssNNRP2oPZyAAEOt1): { Error: www.googleapis.com network timeout. Please try again.
      at FirebaseAppError.Error (native)
      at FirebaseAppError.FirebaseError [as constructor] (/user_code/node_modules/firebase-admin/lib/utils/error.js:25:28)
      at new FirebaseAppError (/user_code/node_modules/firebase-admin/lib/utils/error.js:70:23)
      at TLSSocket.&lt;anonymous&gt; (/user_code/node_modules/firebase-admin/lib/utils/api-request.js:106:51)
      at emitNone (events.js:86:13)
      at TLSSocket.emit (events.js:185:7)
      at TLSSocket.Socket._onTimeout (net.js:339:8)
      at ontimeout (timers.js:365:14)
      at tryOnTimeout (timers.js:237:5)
      at Timer.listOnTimeout (timers.js:207:5)
    errorInfo: 
     { code: 'app/network-timeout',
       message: 'www.googleapis.com network timeout. Please try again.' } }
  </code></pre>
  
  <p>This is due to me (limitation firebase free?) Or an error on the google server and I just have to wait?</p>
  
  <p>My function (I know the function can be improved in speed but the question is not there, I just want to know if I am the reason for this error) This function sends a notification to users who installed the application x day ago, retrieving the day of the creation of their account and their fcm token is saved in the database :</p>
  
  <pre><code>'use strict';
  
  const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  admin.initializeApp(functions.config().firebase);
  
  exports.sendNotificationToNewUser = functions.https.onRequest((request, response) =&gt; {
  
      Date.prototype.sameDay = function(d) {
          return this.getFullYear() === d.getFullYear()
          &amp;&amp; this.getDate() === d.getDate()
          &amp;&amp; this.getMonth() === d.getMonth();
      }
  
      var query = admin.database().ref("users").orderByKey();
      var defaultAuth = admin.auth();
      query.once("value")
      .then(function(snapshot) {
          snapshot.forEach(function(childSnapshot) {
              var user_id = childSnapshot.key;
              var user_data = childSnapshot.val();
  
              admin.auth().getUser(user_id)
              .then(function(userRecord) {
                  var create_date = userRecord.metadata.createdAt
                  var date_now = new Date(Date.now());
                  console.log("Creation date:", create_date);
                  create_date.setDate(create_date.getDate()+4);
                  if (create_date.sameDay(date_now)) {
  
                      var registrationToken = user_data.fcm_token;
  
                      const payload = {
                          notification: {
                              body: "blabla",
                              sound: "default"
                          },
                          "data" : {
                              "key" : "XXX",
                              "value" : "playstore"
                          }
                      };
  
                      var options = {
                          priority: "high",
                          collapseKey: "playstore"
                      };
  
                      // Send a message to the device corresponding to the provided
                      // registration token with the provided options.
                      admin.messaging().sendToDevice(registrationToken, payload, options)
                      .then(function(response) {
                          console.log("Successfully sent message:", response);
                      })
                      .catch(function(error) {
                          console.log("Error sending message:", error);
                      });
                  }
              })
              .catch(function(error) {
                  console.log("Error fetching user data ("+user_id+"):", error);
              });
      });
  });
  response.send("OK");
  })
  </code></pre>