CodexBloom - Programming Q&A Platform

GCP Cloud Functions timeout guide with Firestore integration while using Node.js 14

πŸ‘€ Views: 2 πŸ’¬ Answers: 1 πŸ“… Created: 2025-06-08
google-cloud-functions firestore node.js JavaScript

I'm performance testing and I'm confused about I'm working on a project and hit a roadblock. I'm working with a timeout scenario with my Google Cloud Function that's supposed to write data to Firestore. The function is triggered by an HTTP request, and I've set the timeout to the maximum of 540 seconds. However, it still times out after around 60 seconds. Here’s the relevant portion of my function: ```javascript const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.addDocument = functions.https.onRequest(async (req, res) => { const data = req.body; try { const docRef = await admin.firestore().collection('myCollection').add(data); res.status(200).send(`Document written with ID: ${docRef.id}`); } catch (behavior) { console.behavior('behavior writing document: ', behavior); res.status(500).send('behavior writing document'); } }); ``` I've checked the Firestore quotas and limits, and I'm well below the thresholds. I’m also using the Firestore client version 9.1.1. When I test the function, after about 60 seconds, I get a `504 Gateway Timeout` behavior. To troubleshoot, I added logging to see how long the function is taking, and it seems to hang before it reaches the Firestore write. I've tried increasing the timeout settings in the Google Cloud Console and using different data payloads, but the scenario continues. Is there something I might be overlooking, or a specific best practice when working with Cloud Functions and Firestore that could help resolve this? Any insights would be greatly appreciated! What's the best practice here? Any help would be greatly appreciated! This is happening in both development and production on macOS. My team is using Javascript for this REST API.