5

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

2
  • anyone at the google cloud platform team?
    – mkelle
    Nov 6, 2018 at 7:54
  • In my case local node js emulator timeouts while after deploying it to gcloud it works
    – Ali Zaidi
    Mar 18, 2019 at 14:28

4 Answers 4

4

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.

5
  • does not work, I have set the timeout to 540 sec and I am using the code snippet from the documentation but after about 1.2 minutes or some it fails in postman saying "Could not get any response"
    – Ali Zaidi
    Mar 18, 2019 at 9:45
  • 1
    timeout settings don't work as expected on local but work on live.
    – Ali Zaidi
    Mar 18, 2019 at 14:29
  • @AliZaidi I am currently having this issue in prod environment as well. How did you end up resolving this? Mar 10, 2021 at 15:30
  • @Paul Fabbroni I never had this problem on the google cloud platform, only on the local emulator that I am using. What does the timeout info say in the cloud function details section ibb.co/z8dLNXQ
    – Ali Zaidi
    Mar 12, 2021 at 5:13
  • @AliZaidi a couple weeks later google added a note to their console saying that they have set the timeout to 60 seconds on their testing tab regardless of what you set... thanks Google lol Jun 4, 2021 at 17:47
0

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.

0

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.

0

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.

3
  • By default, a function times out after 1 minute, but you can extend this period up to 9 minutes. cloud.google.com/functions/docs/concepts/exec#timeout
    – smoore4
    Feb 1, 2022 at 14:40
  • @smoore4 That is no news. The news of the answer here is that the message does not adapt to your settings, although the settings work. You still get a message of reaching the 60s limit even if you set it to 540s. Which might explain the whole question above. Feb 1, 2022 at 15:04
  • 1
    just thought it was interesting, hence the comment
    – smoore4
    Feb 1, 2022 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.