gpt4 book ai didi

javascript - 无论代码如何,Firebase 函数超时

转载 作者:行者123 更新时间:2023-12-05 04:54:29 26 4
gpt4 key购买 nike

编辑:2021 年 2 月,此问题已修复。

我一直在使用 node js firebase 函数模拟器处理超时错误。我的功能正在运行,但现在无论代码如何,代码都会等待超时。我尝试复制快速启动页面上的示例,但出现了同样的错误。

我可以在代码中放置控制台语句,但我不会看到任何输出。我有另一个功能可以在创建文档时正常工作。响应出错,但函数将在超时期间继续执行。

const functions = require("firebase-functions");
const admin = require("firebase-admin");

admin.initializeApp();
exports.addMessage = functions.https.onRequest(async (req, res) => {
// Grab the text parameter.
const original = req.query.text;
// Push the new message into Firestore using the Firebase Admin SDK.
const writeResult = await admin.firestore().collection('messages').add({original: original});
// Send back a message that we've successfully written the message
res.json({result: `Message with ID: ${writeResult.id} added.`});
});

Error: Function timed out.at Timeout._onTimeout (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:640:19)at listOnTimeout (internal/timers.js:554:17)at processTimers (internal/timers.js:497:7)i functions: Beginning execution of "createTokenForEvents"⚠ functions: Your function timed out after ~60s. To configure this timeout, seehttps://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation./usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulatorRuntime.js:640throw new Error("Function timed out.");^

编辑:我得出的结论是这个函数确实有效,但它总是出错。当我发现这个错误时,我正在编写另一个函数,甚至当我切换到这个简单的案例时,错误仍然存​​在。然而,在这种情况下,该函数确实创建了一个文档,但是在整个持续时间内保持它的任何东西也可能隐藏了日志语句。我的问题有变化;为什么即使在代码完成后,该函数仍会在整个持续时间内执行。

最佳答案

https://firebase.google.com/docs/functions/terminate-functions

如文档中所述,编写好的函数的原则之一是

Terminate HTTP functions with res.redirect(), res.send(), orres.end().

由于我的其他函数是同步的,所以写一个返回语句就足够了。但是,我通过显式添加终止响应语句 res.end() 来解决错误。我也尝试返回一个 promise ,但它也没有解决问题。

编辑:这个问题在不同的场景中继续发生。使用查询 https://github.com/firebase/firebase-functions/issues/847 时,我确实无法运行代码.截至 2021 年 1 月,就修复社区问题而言,firebase-functions 存储库似乎没有得到维护。一位用户收到了 firebase 团队的回复,称他们一直在尝试解决日志记录问题,但他们没有 promise 解决问题的日期。我什至懒得使用 firebase 函数模拟器。部署函数工作正常。

关于javascript - 无论代码如何,Firebase 函数超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65730167/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com