【问题标题】:Firebase Messaging: app/network-timeout (Error while making request: timeout of 10000ms exceeded) [closed]Firebase 消息:应用程序/网络超时(发出请求时出错:超过 10000 毫秒的超时)[关闭]
【发布时间】:2019-09-11 23:36:42
【问题描述】:

我在节点 JS 服务器上使用 firebase 的管理 SDK。 我注意到,一整批通知通常会在没有明显原因的情况下失败。它在大多数情况下都可以正常工作,并且突然之间,连续 20 条通知显示超时。

完整的错误信息是:

{
  code: "app/network-timeout",
  message: "Error while making request: timeout of 10000ms exceeded."
}

总结我使用的代码:

const admin = require('firebase-admin');
admin.initializeApp({
  credential: [...],
  databaseURL: 'https://[...].firebaseio.com'
});

const message = {
  notification: {
    title: "My title",
    body: "My content"
  },
  token: token
}

admin.messaging().send(message)
    .then((response) => {
      // message sent with success (most of the time)
    })
    .catch((err) => {
      // message error: timeout
    })

我认为这可能与定价计划有关,因为我通常在使用 Firebase 的有限功能时遇到这种故障,但消息在定价计划中显示为“免费”。无论如何我都切换到 spark 以防万一,我会监控任何变化。

我找不到任何人报告此类问题,知道为什么我随机使用 Firebase 消息传递超时?

【问题讨论】:

  • 您是否要同时发送大量消息?它可能会对 Node.js 进程造成负担,导致某些操作排队并超时。此外,如果您使用的是 v8.2.0 或更高版本,SDK 还会在抛出错误之前重试 ETIMEDOUT 错误大约 4 次。确保您使用的是最新版本。

标签: node.js firebase firebase-cloud-messaging firebase-admin


【解决方案1】:

错误消息提示我您的服务器暂时无法访问 FCM 服务器。就是说超过了10秒的超时时间。如果您收到此错误消息,则应重试 API 以发送该消息。

网络问题确实时有发生,并且您的服务器和 Firebase 之间可能有十几个您无法控制的网络跃点。网络故障重试对于容错始终很重要。

【讨论】:

  • 好的,我只是想检查一下除了服务器/网络可靠性问题之外是否还有其他可能,谢谢,我会重新安排超时通知。
猜你喜欢
  • 2019-02-28
  • 2015-01-05
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 1970-01-01
  • 2021-08-25
  • 1970-01-01
  • 2022-01-26
相关资源
最近更新 更多