Google Cloud Function Not Terminating Past Max Function Duration

585 views Asked by At

In the Google Cloud Functions documentation under the Time Limits section, it says that the max duration should be 540 seconds. After that the cloud function should terminate.

"Max function duration - The maximum amount of time a function can run before it's forcibly terminated - 540 seconds"

I've ran some tests on http-triggers and noticed that if a response is not sent back within 6 seconds the function terminates.

I also ran another test that sent back a response immediately and asynchronously logs a message every minute.

Currently after 40 minutes, it's still logging a message.

Here is the code snippet:

function recursiveCallback (n) {
    console.log(`MarkTest: Callback Pass ${n}`);
    setTimeout(function () {
        recursiveCallback(n + 1);
    }, 1000 * 60);
}

exports.test_func = function (req, resp, callback) {
    console.log('Sending Response. response');
    resp.send('');
    console.log('Response Sent.');
    console.log('Starting Async Polling');
    recursiveCallback(0);
    console.log('test_func End')
};

Is this a bug, or is this intentional?

1

There are 1 answers

0
Bret McGowen On

1) I haven't seen the 6 second HTTP timeout, can you provide any steps to reproduce?

2) Cloud Functions currently (Feb 2018) doesn't forcefully stop functions after the timeout has elapsed if there are still async tasks in flight; the CPU throttles down but the function may run for an (undefined) amount of time. The original idea was to let minor cleanup/background work finish before stopping the function. However, we're likely to change this behavior to stop the function at timeout, as the current behavior can cause confusion for developers, since it's not guaranteed or documented how much longer the function can run, and under what circumstances.