0
votes

If you run a simple example like this locally:

export async function runTimeout(req, res) {
    // console.log('Request:\n\n', req);
    return new Promise(async (resolve, reject) => {
        await timeout(80000);
        resolve();
    });
    res.status(200).send('Timeout complete');
}

function timeout(ms) {
    return new Promise((resolve) => setTimeout(resolve, ms));
}

Using the commands:

firebase serve --only functions

You will see that this times out at 60 seconds every time, according to the firebase github issues list the default for localhost should now stand at 9 minutes (which is the max) so their is no need to configure it. Does anyone know why I am timing out at 60 seconds vs being able to complete the full 80 seconds (as in this example) or more?

The error message is:

info: Execution took 62033 ms, finished with status: 'timeout' info: Execution took 62043 ms, finished with status: 'crash' error: Something went wrong with the function! error: Error: Can't set headers after they are sent. at validateHeader (_http_outgoing.js:491:11) at ServerResponse.setHeader (_http_outgoing.js:498:3) at ServerResponse.header (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:767:10) at ServerResponse.send (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:170:12) at ServerResponse.json (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:267:15) at ProxyServer.Supervisor._proxy.on (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/@google-cloud/functions-emulator/src/supervisor/supervisor.js:107:14) at ProxyServer.emit (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/eventemitter3/index.js:144:27) at ClientRequest.proxyError (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:156:18) at emitOne (events.js:116:13) at ClientRequest.emit (events.js:211:7)

1

1 Answers

5
votes

The default timeout for all deployed functions is 60 seconds. When the function timeout duration elapses, Cloud Functions will clamp down resources on your function, causing it terminate, and leave that error in your log.

You can configure the timeout of your function deployed by the Firebase CLI in the Cloud console (not in the Firebase console, and not by the CLI, currently). The maximum timeout is 540 seconds (9 minutes).

Also, there are perhaps one significant error in your function that may make it behave differently than you expect. You are returning a promise from runTimeout that prevents the following line (res.send) from ever executing, under any circumstance. If you don't send a response to the client, your function will also timeout, as the sent response marks the end of your function's execution.