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?
Hi @hpirttin,
Welcome to Google Cloud Community!
The error message DEADLINE_EXCEEDED indicates that your Cloud Function is taking longer than its configured timeout limit to complete the Firestore read operation. Below are the possible causes for the error message and their workarounds:
Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.