执行耗时 60006 毫秒,完成状态为:'timeout'

Sha*_*aun 0 node.js firebase google-cloud-functions

如果您在本地运行这样的简单示例:

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));
}
Run Code Online (Sandbox Code Playgroud)

使用命令:

firebase serve --only 功能

您将看到每次超时时间为 60 秒,根据 firebase github 问题列表,本地主机的默认值现在应为 9 分钟(这是最大值),因此无需对其进行配置。有谁知道为什么我在 60 秒时超时而不是能够完成完整的 80 秒(如本例所示)或更长时间?

错误信息是:

信息:执行耗时 62033 毫秒,完成状态:“超时”信息:执行耗时 62043 毫秒,完成状态:“崩溃”错误:函数出现问题!错误:错误:发送后无法设置标头。在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) 在 ServerResponse.send (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/express/ lib/response.js:170:12) 在 ServerResponse.json (/Users/hackintosh/.nvm/versions/node/v8.11.2/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:267 :15) 在 ProxyServer.Supervisor._proxy。

Dou*_*son 5

所有已部署函数的默认超时为 60 秒。当函数超时持续时间结束时,Cloud Functions 将限制您的函数上的资源,导致它终止,并将该错误留在您的日志中。

您可以在 Cloud 控制台中配置由 Firebase CLI 部署的函数的超时时间(当前不在 Firebase 控制台中,也不能在 CLI 中)。所述最大超时为540秒(9分钟)。

此外,您的函数中可能存在一个重大错误,可能会使其行为与您预期的不同。您正在从 runTimeout 返回一个承诺,以防止在任何情况下执行以下行 (res.send)。如果您不向客户端发送响应,您的函数也会超时,因为发送的响应标志着函数执行的结束。