Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Firestore reading is not always successful.

I am using cloud functions Gen2 in Cloud Run. The trigger is pub/sub. I am trying to read device information from Firestore. This works about 90% of the time, but fails too often. I get the following error message: Error: 4 DEADLINE_EXCEEDED: Deadline Exceeded. Here is how I try to read data from firestore.

 

 

async function readDeviceData(deviceId) {
  try {
    const devRef = firestore.collection(DEVICE_COLLECTION_NAME).doc(deviceId);
    var doc = await devRef.get();
    if (doc.exists) {
      return Promise.resolve(doc.data());
    } else {
      return Promise.resolve();
    }
  } catch (error) {
    console.log("ERROR: READ", error);
    return Promise.resolve();
  }
}

 

 

The failed read commands occurred around 10:00 PM (see image -> Request latencies). There are several failed read commands during that time, at other times it works OK. What could be the cause? I use a similar read command on the Gen1 side and have had no problems. Should I move this to Gen1?

  Näyttökuva 2025-05-09 kello 13.58.09.png

0 0 20
0 REPLIES 0