How to configure timeout of Firebase functions on local

6.4k views Asked by At

I want to do some intense job on firebase functions and it usually takes more than 60 seconds. On production, I can set timeout longer from web console but I cannot find setting for local environment.

Following is the command which I'm using to start serving.

firebase serve --only functions

I'm using HTTPS trigger and following is the command to trigger my function on local.

functions-emulator call myfunc --data='{"uid":"user_id_1"}'

Is there way to configure timeout on local?

4

There are 4 answers

1
Youssef Saber On BEST ANSWER

You can set the timeout and memory options in local using the RunWith function

const runtimeOpts = {
 timeoutSeconds: 300,
 memory: '1GB'
}

exports.myStorageFunction = functions
.runWith(runtimeOpts)
.storage
.object()
.onFinalize((object) = > {
  // do some complicated things that take a lot of memory and time
});

The maximum value for timeoutSeconds is 540, or 9 minutes. Valid values for memory are:

128MB
256MB
512MB
1GB
2GB

3
aofdev On

You can set the time more than 60 seconds.

Default timeout can be changed here: Console Cloud functions


select function -> name function -> edit -> timeout

0
SuttonY On

I struggled with this for a while, but finally found this solution:

  • In your functions directory, add a file named .env.local
  • Add this single line to that file: FUNCTIONS_EMULATOR_TIMEOUT_SECONDS=540s
  • Perform the build of your functions.
  • Shut down and then restart your local emulator. The timeout set in this new .env.local file should be honored.

h/t to volkyeth for the related GitHub firebase issue response: https://github.com/firebase/firebase-tools/issues/2837#issuecomment-1048878134

0
most200 On

There is a known issue with the Firebase emulator ignoring runWith({timeoutSeconds: }) when running Firebase functions locally.

Until Firebase fixes this, @SuttonY's answer provides one solution for changing the timeout setting locally, which is to create an .env.local file.

Another solution is to set the timeout variable in the command line when you run the Firebase emulator. For example, this is the command I use to start my emulator:

FUNCTIONS_EMULATOR_TIMEOUT_SECONDS=540 firebase emulators:start --only functions

Credit to @tiagohillebrandt for finding and posting this on the open GitHub issue. https://github.com/firebase/firebase-tools/issues/2837