【问题标题】:Firebase Error: Process exited with code 16 at process.<anonymous>Firebase 错误:进程以代码 16 退出进程。<匿名>
【发布时间】:2020-12-24 04:25:20
【问题描述】:

我不断收到此错误,不太确定发生了什么。

queueFunction
Error: Process exited with code 16
at process.<anonymous> (/layers/google.nodejs.functions- 
framework/functions-framework/node_modules/@google-cloud/functions- 
framework/build/src/invoker.js:275:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at process.exit (internal/process/per_thread.js:167:15)
at Object.sendCrashResponse (/layers/google.nodejs.functions- 
framework/functions-framework/node_modules/@google-cloud/functions- 
framework/build/src/logger.js:37:9)
at process.<anonymous> (/layers/google.nodejs.functions- 
framework/functions-framework/node_modules/@google-cloud/functions- 
framework/build/src/invoker.js:271:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at processPromiseRejections (internal/process/promises.js:209:33)
at processTicksAndRejections (internal/process/task_queues.js:98:32)

queueMatch
Error: Process exited with code 16
at process.<anonymous> (/layers/google.nodejs.functions- 
framework/functions-framework/node_modules/@google-cloud/functions- 
framework/build/src/invoker.js:275:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at process.exit (internal/process/per_thread.js:167:15)
at Object.sendCrashResponse (/layers/google.nodejs.functions- 
framework/functions-framework/node_modules/@google-cloud/functions- 
framework/build/src/logger.js:37:9)
at process.<anonymous> (/layers/google.nodejs.functions- 
framework/functions-framework/node_modules/@google-cloud/functions- 
framework/build/src/invoker.js:271:22)
at process.emit (events.js:315:20)
at process.EventEmitter.emit (domain.js:483:12)
at processPromiseRejections (internal/process/promises.js:209:33)
at processTicksAndRejections (internal/process/task_queues.js:98:32) 

这是针对我创建的函数,该函数有时似乎执行,然后不执行。

exports.queueFunction = globalFunctions.runWith(runtimeOpts).https.onRequest((request, response) => {

try {
    challengeId = '';
    console.log("Running cron challenge...")
    var timesRun = 0;
    var interval = setInterval(() => {
        timesRun += 1;
        if (timesRun === 12) {
            console.log("Stopping cron challenge interval...")
            clearInterval(interval);
        }
        console.log("Executing challenge match...")
        getChallenges();
    }, 5000);
    response.status(200).send({ success: 'success' });
} catch (error) {
    response.status(500).send({ error: 'error' });
}

});

队列只是检查集合中是否存在匹配队列

db = admin.firestore();
const tourRef = db.collection('ChallengeQueue');
const snapshot = await tourRef.where('challengeId', '==', challengeId).get();
const queuedata = [];
if (snapshot.empty) {
    console.log('No users online.');
    return;
}
snapshot.forEach(doc => {
    if (doc.id !== playerId) {
        queuedata.push(doc.data());
    }
});

【问题讨论】:

  • 在 Stack Overflow 上,请不要显示文字和代码的图片。将文本复制到问题本身并设置格式,以便于阅读、复制和搜索。您可以使用底部的编辑链接编辑问题以更正此问题。
  • 感谢@DougStevenson 指出...认为这将有助于识别错误
  • 如果您只是将文本复制到问题中会更有帮助。屏幕截图本身没有添加任何内容 - 重要的是文本。 Please read this..
  • This answer 表明这是由unhandledExceptionunhandledRejection 事件引起的。由于您的异步代码中缺少 .catch() 或 try-catch 块,您可能会遇到未处理的拒绝。在您的代码中添加一些错误处理,问题应该会消失,或者至少会变得显而易见。

标签: javascript firebase google-cloud-firestore google-cloud-functions


【解决方案1】:

根据给出的错误信息,给定的queueFunction与它无关,因为它是queueMatch函数中的错误。

请提供globalFunctionsruntimeOpts 对象。目前我只能假设globalFunctions被定义为import * as globalFunctions from "firebase-functions"

关于为什么您的间隔有时会运行,这是因为您发出信号表明该函数已准备好在任何间隔回调运行之前终止(见下文)。一旦返回响应,“函数执行器”被认为可以安全关闭 - 在发送响应后您不应该发生任何重要的事情。

您的代码在功能上等同于:

exports.queueFunction = globalFunctions.runWith(runtimeOpts).https.onRequest((request, response) => {

  try {
      challengeId = '';
      console.log("Running cron challenge...")
      var timesRun = 0;
      var interval = 1 /* some number representing the ID of the interval */;
      response.status(200).send({ success: 'success' }); // response sent, terminate function
  } catch (error) {
      response.status(500).send({ error: 'error' }); // response sent, terminate function
  }

});

注意:在上面的代码块中,假设“终止函数”意味着立即调用process.exit()。实际上,“函数执行器”不会立即终止,但您的代码应该假定它是。

【讨论】:

  • 谢谢山姆,我已经用正确的图像编辑了我的问题。 const globalFunctions = functions.region('europe-west1');const runtimeOpts = { timeoutSeconds: 300, memory: '1GB' }; 两个函数都存在同样的问题
  • @Shina 您能否尝试等待间隔结束后再从函数返回?之后,更新问题,说明错误是否仍然存在。正如这个答案所指出的,这个问题很可能是由 CF 过早终止引起的。为了实现预期的功能,您可以使用 12 次迭代的循环和 synchronous wait。如果在解决后您遇到任何其他问题,请使用当前状态更新您的问题。
猜你喜欢
  • 2021-12-06
  • 1970-01-01
  • 1970-01-01
  • 2018-03-06
  • 1970-01-01
  • 1970-01-01
  • 2017-11-20
  • 2018-11-06
  • 1970-01-01
相关资源
最近更新 更多