'Google Cloud Function Timeout Setting doesn't work

I can't get a Google Cloud Function to run for more than 60secs, even when the timeout is set to 540secs!! Any suggestions?

I set the timeout flag on deployment to --timeout=540, and I know the setting goes through, because the 540 sec timeout setting appears in the GCP WEB UI. I have also tried to manually edit the timeout to 540 through the GCP WEB UI. But in any case i still get the DEADLINE_EXCEEDED after just ~ 62000 ms.

I have tried both the pub/sub and https methods as the func trigger, but still get the premature function timeout at ~60s.

Im running the latest CLI, with these these func settings:

  • trigger: http/pubsub (both tested, same result)
  • availableMemoryMb: 2048
  • runtime: nodejs6
  • status: ACTIVE
  • timeout: 540s

Thanks for any inputs!

Br Markus



Solution 1:[1]

I have used the documentation code for delay and executed a Cloud Function with the same specifications as yours. In the documentation, the execution is delayed 120000 ms (2 mins). I edited that and put it at 500000 ms. This plus the normal time that the CF takes to execute, will reach the desired execution time (around 9 minutes). If you add 540000 to test the code, it will execute with timeout error at ~540025, because the value itself is exceeding the timeout limit of the Cloud Function and at the same time the default maximum timeout limit of a Cloud Function, which is 9 minutes.

I also tried the creating the function using this command gcloud functions deploy [FUNCTION_NAME] --trigger-http --timeout=540. After successful deployment, I updated the code manually in the GCP Cloud Function UI as follows

exports.timeoutTest = (req, res) => {
  setTimeout(() => {
    let message = req.query.message || req.body.message || 'Hello World today!';
    res.status(200).send(message);
    res.end();
  }, 500000); 
};

Both times the Cloud Function was executed and returned with status code 200. This means that you can set a timeout to be more than 60 secs which is the default value.

If you revised everything correctly and you still have this issue, I recommend you to start afresh, create a new CF and use the documentation link I provided.

Solution 2:[2]

The 60 seconds timeout is not resulting from GCP Cloud Function setting. For instance if this is a Django/Gunicorn App, the timeout is coming from the timeout of gunicorn that is set in app.yaml

entrypoint: gunicorn -t 3600 -b :$PORT project_name.wsgi

For instance, this will achieve a timeout of 3600 seconds for gunicorn.

Solution 3:[3]

I believe I'm some years late but here is my suggestion.

If you're using the "Test the function" button in the "Testing tab" of the Cloud Function (in the gcp "Cloud Console") it says right next to the button that:

Testing in the Cloud Console has a 60s timeout. Note that this is different from the limit set in the function configuration.

I hope you fixed it and this answer can help someone in the future.

Solution 4:[4]

Update: Second try ("Test the function") was precisely 9 minutes

From: 23:15:38

Till: 23:24:38

And it is exactly the 9 minutes, although the message again was about 60 seconds only and popped up much earlier than the actual stop.

enter image description here

enter image description here

Function execution took 540004 ms, finished with status: 'timeout'

enter image description here

This time with a lot of memory (2 GB), timeout clearly made it stop. The message is perhaps just popping up earlier since it has not been programmed in detail, my guess. You should always look at the logs to see what is happening.

I guess that the core of your question is outdated then: At least in 01/2022, you do have the demanded timeout time regardless of the what you may read, and you just should not care about the messages.

First try ("Test the function") 8 minutes after reached memory limit

A screenshot of how it looks like in 2022/01 if you get over the 60 seconds (with 540s maximum timeout for this example function set in the "Edit" menu of the CF):

Function being tested has exceeded the 60s timeout imposed by the Cloud Functions testing utility.

Yet, in reality, when using just the "Testing tab" the timeout is at least after 300s / 5 minutes which can be seen next to the "Test the function" button:

Testing in the Cloud Console has a 5 minute timeout. Note that this is different from the limit set in the function configuration.

enter image description here

enter image description here

But it is even more. I know from testing (started from the "Testing tab" --> "Test Function" in the Cloud Function) that you have at least 8 minutes:

From 22:31:43:

enter image description here

Till 22:39:53

enter image description here

And this was at first stopped by the 256 MB limit, secondly only by time (a bit unclear why there were both messages).

Therefore, your question about why you get only 60 seconds timeout time might rather ask why these messages are wrong (like in my case). Perhaps GCP did not make the effort to parametrize the messages for each function.

Perhaps you get even slightly more time when you start with gcloud from terminal, but that is not so likely since 9 minutes are the maximum anyway.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 london_utku
Solution 3 questionto42standswithUkraine
Solution 4