GCP Cloud Functions Timing Out with Firestore Document Retrieval - 'Execution Timeout' scenarios
I can't seem to get I'm experiencing a timeout scenario with my Google Cloud Function that's triggered by Firestore document changes. The function is supposed to retrieve a document from Firestore, process it, and then update another collection based on the document's data. However, I'm getting an 'Execution Timeout' behavior after 60 seconds, even though the Firestore read operation is expected to be much quicker. Hereβs a snippet of my Cloud Function: ```javascript const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.processDocument = functions.firestore.document('sourceCollection/{docId}').onWrite(async (change, context) => { const docId = context.params.docId; // Attempting to read a document const docRef = admin.firestore().collection('sourceCollection').doc(docId); const docSnapshot = await docRef.get(); if (!docSnapshot.exists) { console.log('No such document!'); return; } const data = docSnapshot.data(); // Simulating some processing logic await admin.firestore().collection('targetCollection').add({ processedData: data }); console.log('Document processed successfully'); }); ``` I've tried increasing the timeout in the function settings to 120 seconds, but the scenario continues, and I suspect it might be related to how Firestore handles reads under heavy load or the function's cold start latency. I also checked for any existing indexes in Firestore that might be impacting performance, but everything seems fine. Has anyone encountered similar issues or have insights on optimizing Firestore reads within Cloud Functions? Any suggestions for debugging or improving the performance would be greatly appreciated. This is part of a larger application I'm building. I'm working with Javascript in a Docker container on macOS. Any ideas what could be causing this?