Firebase 功能:不清楚“连接错误"; [英] Firebase Functions: Unclear "connection error"

查看:23
本文介绍了Firebase 功能:不清楚“连接错误";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次使用我的 HTTP Firebase Cloud Function 运行时,我都会收到此错误:

I am getting this error every so many runs with my HTTP Firebase Cloud Function:

函数执行耗时 ****ms,完成状态为:'connection error'

它的发生不一致,但我不能完全缩小问题所在.我不相信错误出现在我的应用程序中,因为它没有显示错误打印输出.在运行此云功能时,我自己与 firebase 的连接并没有中断.

It happens inconsistently but I can't quite narrow down what the problem is. I don't believe the error is in my app as it's not showing an error printout. And my own connection with firebase while running this cloud function isn't cutting out.

任何想法为什么 Firebase 会随机导致云函数执行失败并出现连接错误"?

Any ideas why Firebase randomly fails cloud function executions with "connection error"?

推荐答案

函数执行耗时 ****ms, finished with status: 'connection error' 有两个主要原因:

  1. 在使用 Spark 计划时尝试调用非 Google 服务(请参阅定价页面).这可以通过升级到付费计划来解决.
  1. Trying to call a non-Google service while on the Spark plan (see pricing page). This can be fixed by upgrading to a paid plan.


  1. 函数不知道 promise 是否已解决.如此处文档中所述,每个承诺都必须返回.还有一篇博文(附有帮助视频!) 关于这个.
  1. A function doesn’t know whether a promise resolved or not. Every promise must be returned, as mentioned in the docs here. There is also a blog post (with helpful video!) about this.

几个未返回的承诺示例:

A couple of examples of unreturned promises:

exports.someFunc = functions.database.ref('/some/path').onCreate(event => {
     let db = admin.database();

     // UNRETURNED PROMISE
     db.ref('/some/path').remove();

     return db.ref('/some/other/path').set(event.data.val());
});

exports.makeUppercase = functions.database.ref('/hello/{pushId}').onWrite(event => {
    return event.data.ref.set('world').then(snap => {

      // UNRETURNED PROMISE
      admin.database().ref('lastwrite').set(admin.database.ServerValue.TIMESTAMP);

    });
});

exports.makeUppercase = functions.database.ref('/hello/{pushId}').onWrite(event => {

    // UNRETURNED PROMISE
    event.data.ref.set('world').then(snap => {
        return admin.database().ref('lastwrite').set(admin.database.ServerValue.TIMESTAMP);
    });
});

为了帮助在部署代码之前发现这个错误,请查看 这个 eslint 规则.

To help catch this mistake before deploying code, check out this eslint rule.

要深入了解 Promise,这里有一些有用的资源:

For an in-depth look at promises, here are some helpful resources:

这篇关于Firebase 功能:不清楚“连接错误";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆