I am running a node.js cloud function in firebase and testing locally using the firebase server (functions only)
firebase serve --only functions
I’m having a premature timeout issue that is only effecting me (as opposed to both a colleagues of mine, and also in production on gcloud) – but it’s extremely difficult to build/test on.
At some point it seems to decide the function is now over and timed out at 540s (even if its been just a few seconds)
⚠ functions: Your function timed out after ~540s. 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.
Then it seems to kill the function and decide to pick up its toys and go home.
The problem is most apparent in loops that have a deliberate “delay” built in to avoid DoS’ing APIs. It’s almost as if when this goes quiet for a few seconds, firebase thinks its finished and terminates the call.
example error
You can see at some point firebase has declared the function over:
**i functions: Finished "http.app" in 949.993542ms**
I’ve tried all the different ways you can “delay” a node app from cpu cycling to set timeouts… here’s my current function (but the same issue occurs no matter how I delay)
function waitforme(milisec) {
return new Promise(resolve => {
setTimeout(() => { resolve(''); }, milisec);
})
}
Ive tested it on simple loops that have nothing else but the delay in them, and after a few seconds (regardless of how long the delay per loop is) it appears that the function is terminated.
It feels like the server is terminating its connection if it doesn’t hear anyone else on the line – but it’s doing it extremely quickly… despite being run with ample time.
.runWith({
timeoutSeconds: 540,
memory: "4GB",
})
Hopefully someone can help!