3

Note: i've set this up with Firebase Functions.

Emulator
When my firebase function takes more than 5 seconds, it returns
{ code: "ECONNRESET" }

The console shows:
functions: Your function timed out after ~300s. To configure this timeout, see
(although it endured only 5 seconds)

No matter the amount of timeoutSeconds set below.

const functions = require("firebase-functions");
const cors = require('cors')({
  origin: true,
});

exports.app = functions.runWith({
  timeoutSeconds: 300
}).https.onRequest((req, res) => {
  cors(req, res, () => {
    setTimeout(() => res.send({result: 'success'}), 5000);
  });
});

This problem occurs in the emulator firebase emulators:start --only functions

Also strange behavior in the console when the server responds after 4 seconds. It says after five seconds that it times out after 300 sec, although the app already finished:

i  functions: Beginning execution of "app"
i  functions: Finished "app" in 4102.929386ms
⚠  functions: Your function timed out after ~300s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
⚠  Your function was killed because it raised an unhandled error.

Deployed When I deploy it, then the url shows this result, although I use cors

Error: Forbidden
Your client does not have permission to get URL /app from this server.

The versions in package.json

  "dependencies": {
    "firebase-admin": "^10.3.0",
    "firebase-functions": "^3.18.0"
  },

The documentation for: runWith

Wim den Herder
  • 1,197
  • 9
  • 13
  • 2
    Please share the entire function code and execution log. You might be doing something wrong. We need to be able to reproduce what you've done. – Doug Stevenson Nov 29 '22 at 17:18
  • 2
    You should use a cors module instead of trying to implement it yourself. I don't think you're doing it correctly. https://stackoverflow.com/questions/42755131/enabling-cors-in-cloud-functions-for-firebase – Doug Stevenson Nov 29 '22 at 18:50
  • @DougStevenson that didn't solved the cors issue unfortunately, i've updated my code above so you can see it, thanks – Wim den Herder Nov 29 '22 at 19:07
  • Do you have any solution? I have the exact same problem and can't find what is wrong. – Mathieu Feb 08 '23 at 14:38
  • It seems like it is only in the emulator though, when I deploy it, things seem to work. – Mathieu Feb 08 '23 at 14:49

1 Answers1

0

runWith options did not work locally for me. I had to set this local env variable FUNCTIONS_EMULATOR_TIMEOUT_SECONDS https://stackoverflow.com/a/72396726/10668719.

But in regards to your functions timing out before the set timeout value. I ran into this problem when running in node v20

Found this github issue https://github.com/firebase/firebase-tools/issues/5363 The problem was fixed once I downgraded to node 18

Fbog
  • 1
  • 2