So I recently needed to run a function in cloud functions that takes quite a long time to run. TLDR: I needed to do a time sensitive thing 157 times whilst using the local firebase functions emulator.
No matter what I tried every time I reached iteration number 57 I would see the error: Your function timed out after ~60s. To configure this timeout, see https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
You can follow the URL but the “runWith” method didn’t work for me at all. In fact this is a known issue: https://github.com/firebase/firebase-tools/issues/2837
exports.internalBatchArrayIntoChunks = functions.runWith({ timeoutSeconds: 540, memory: "1GB" }).https.onRequest(async (req, res) => {
// Do some complicated things that take a lot of memory and time
res.sendStatus(200);
Still got the same error:
> 53
> 54
> 55
> 56
> 57
! functions: Your function timed out after ~60s. To configure this timeout, see https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
> C:\src\nvm\v16.0.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:634
> throw new Error("Function timed out.");
>
>
> Error: Function timed out.
> at Timeout._onTimeout (C:\src\nvm\v16.0.0\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:634:19)
> at listOnTimeout (node:internal/timers:557:17)
> at processTimers (node:internal/timers:500:7)
The best way I could find to solve this was to create a file inside of the functions directory called: “.env.local”
Inside the file we place the timeout we wish to use:
FUNCTIONS_EMULATOR_TIMEOUT_SECONDS=540s
When you are ready, close the emulator process in the terminal and restart it.
Hope this helps you.
if(window.strchfSettings === undefined) window.strchfSettings = {}; window.strchfSettings.stats = {url: "https://itskofio.storychief.io/en/firebase-cloud-functions-emulator-your-function-timed-out-after-60s?id=251583717&type=26",title: "Firebase Cloud Functions Emulator | Your function timed out after ~60s",id: "46ac73b7-33eb-4344-b51f-39dd7bede810"}; (function(d, s, id) { var js, sjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {window.strchf.update(); return;} js = d.createElement(s); js.id = id; js.src = "https://d37oebn0w9ir6a.cloudfront.net/scripts/v0/strchf.js"; js.async = true; sjs.parentNode.insertBefore(js, sjs); }(document, 'script', 'storychief-jssdk'))